<?php

namespace App\Http\Controllers\Api;

use App;
use App\Util\Common;
use App\Util\GetMac;
use App\Util\SqlServerUtil;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use function Symfony\Component\Debug\header;
use Illuminate\Support\Facades\Storage;
use Excel;
use phpDocumentor\Reflection\DocBlock\Tags\Var_;

use Illuminate\Support\Facades\Log;

class BJController extends CommonController
{
    protected $response = [
    		"Error" => 0,
    		"Message" => "Success!",
    		"Data" => []
	];
    
    /**
    * 船检参数设置 列表
    * @date: 2023年1月12日 上午9:51:42
    * @author: juyi
    */
    public function vxeCjSetList(Request $request){
    	if(!isset($page)) $page =1;
    	$limit= $request ->get('pageSize');
    	if(!isset($limit)) $limit = 20;
    	$FRepKey = $request->get('FRepKey');
    	
    	$keywordStr ='';
    	if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
    		$keyword =  $request->keyword ;
    		$keywordStr=" and (charindex('{$keyword}',v1.ftype)>0  )";
    	}
    	
    	$ftypeStr ='';
    	if ($request->has('ftype') and $request->ftype != '' and !empty($request->ftype)) {
    		$ftype =  $request->ftype ;
    		$ftypeStr=" and  v1.ftype  = '{$ftype}' ";
    	}
    	
    	$sql = " select row_number() over(order by v1.fsort) as rownumber
 ,v1.* from gz_YchuanjianfSet  v1  where 1=1 {$keywordStr}  {$ftypeStr} " ;
    	$sql=" select top $limit * from ( $sql ) temp_row where rownumber>(($page-1)*$limit)";
//     	echo $sql;die;
    	$res = SqlServerUtil::execTosqlOK($this->SqlServer,  $sql) ; 
    	$result = [];
    	if($res){
    		$result = arrayToLowerToNum($res);
    	}
    	
    	$countSql ="SELECT COUNT(1) AS total FROM  gz_YchuanjianfSet  v1  where 1=1 {$keywordStr}  {$ftypeStr} ";
    	$count = SqlServerUtil::execToSql($this->SqlServer, $countSql ,2);
    	$total = isset($count['total']) ? $count['total']:0;
    	$this->response['total'] = $total;
    	$this->response['pageSize'] = $limit;
    	$last_page = 0;
    	if($count && count($count)>0){
    		$last_page = !empty($total) ? ceil($total/$limit):0;
    	}
    	
    	$this->response['Data'] = $result;
    	$this->response['currentPage'] = $page;
    	$this->response['lastPage'] = $last_page;
    	return response()->json($this->response);
    	
    }
    
    /**
     * 船检参数设置 新增
     * @date: 2023年1月12日 上午9:51:42
     * @author: juyi
     */
    public function vxeCjSetAdd(Request $request){
    	$FRepKey= $request->get('FRepKey');
    	if(strval($FRepKey) == '26024_1'){
    		$FRepKey = '2602401' ;
    	 }
    	$db = columnBiao($FRepKey);//表名  -- 
    	$opername  = $request->opername?$request->opername:'' ;
    	$data =  $request->all() ;
    	
    	$getVexTableColumnData = $this->getVexTableColumn($FRepKey  ) ;
    	//取参数问题
    	$CsData =  $this->getSystemProfile();
    	//汇率
    	$huilv = $CsData['fsethuilv']; 
    	 
    	// 新增 -- insertRecords,
    	$insertRecords = isset($data['insertRecords'])?$data['insertRecords'] :[];
    	if(!empty($insertRecords)){
    		$insData=[];
    		 
    		foreach ($insertRecords as $k =>&$v)
    		{
    			foreach ($getVexTableColumnData as $kc=>$vc)
    			{
    				if( ( empty($v[$vc['frepfld']]) || $v[$vc['frepfld']] =='.00' ) && $vc['freptype'] == 131 ){
    					$v[$vc['frepfld']] =0;
    				}
    				
    				if( empty($v[$vc['frepfld']])  && ($vc['freptype'] == 202 || $vc['freptype'] == 200 ) ){
    					$v[$vc['frepfld']] = '';
    				}
    				$insData[$k][$vc['frepfld']] = $v[$vc['frepfld']] ;
    				
    			}
    			//汇率问题
    			if($v['ftype']  == 'ABS'){
    				$insData[$k]['fhuilv'] = $huilv ;
    			}else{
    				$insData[$k]['fhuilv'] = 1 ;
    			}
    			
    		}
    		
    		SqlServerUtil::sqlsrvAllTosql($this->SqlServer ,$db , $insData);
    		$this->writeLog(getMkName($FRepKey),'新增' , $FRepKey , $insData ,$opername );
    	}
    	
    	// 修改 --  updateRecords,
    	$updateRecords = isset( $data['updateRecords'])?$data['updateRecords'] :[];
    	$fidField = 'fid';
    	if(!empty($updateRecords)){
    		foreach ($updateRecords as $kup=>&$vup)
    		{
    			$insData =[];
    			$where= [];
    			$where[$fidField] = $vup[$fidField];
    			 
    			foreach ($getVexTableColumnData as  $up)
    			{
    				if( ( empty($vup[$up['frepfld']]) || $vup[$up['frepfld']] =='.00' ) && $up['freptype'] == 131 ){
    					$vup[$up['frepfld']] =0;
    				}
    				
    				if( empty($vup[$up['frepfld']])  && ($up['freptype'] == 202 || $up['freptype'] == 200 ) ){
    					$vup[$up['frepfld']] = '';
    				}
    				
    				$insData[$up['frepfld']] = $vup[$up['frepfld']] ;
    			}
    			
    			//汇率问题
    			if($vup['ftype']  == 'ABS'){
    				$insData['fhuilv'] = $huilv ;
    			 }else{
    			 	$insData['fhuilv'] = 1 ;
    			 }
//     			 dd($insData);
    		 
    			SqlServerUtil::exeupdateTosql($this->SqlServer,$db,$insData,$where);
    			$this->writeLog(getMkName($FRepKey),'修改' , $FRepKey , $insData ,$opername );
    		}
    		
    	}
    	
    	//删除 --  removeRecords
    	$removeRecords = isset( $data['removeRecords'])?$data['removeRecords'] :[];
    	if(!empty($removeRecords)){
    		$Fids =[];
    		$Fids = join("','", array_column($removeRecords, 'fid'));
    		SqlServerUtil::sqlsrvDelete($this->SqlServer,$db, ['fid'=>"'".$Fids ."'" ],true);
    		$this->writeLog(getMkName($FRepKey),'删除' , $FRepKey , $removeRecords ,$opername );
    	}
    	
    	showMsg(0,'成功' );
    	
    }
    
    
    //更新主控隐藏
    public function accessField(Request $request){
    	//fobjhide
    	$all = $request->all();
//     	dd($all);
    	$data = [];
    	$select = $all['select'];
    	$selectedLeftData = $all['selectedLeftData'];
    	$opername = isset($all['opername'])?$all['opername']:'';
    	if($select){
    		foreach ($select as $k=>&$v)
    		{
    			$v['fname'] = $selectedLeftData['fname'];
    			$v['fgroupid'] = $selectedLeftData['id'];
    		}
    		
    		SqlServerUtil::sqlsrvDelete($this->SqlServer,'gz_ObjectAccessField',[ 'fgroupid' =>$selectedLeftData['id']]);
    		// gz_ObjectAccessField
    		$in = SqlServerUtil::sqlsrvAllTosql($this->SqlServer,'gz_ObjectAccessField',$select);
    		$this->writeLog('权限操作','公共设置' , 13001 , ($select) ,$opername );
    	}else{
    		$in =true;
    		SqlServerUtil::sqlsrvDelete($this->SqlServer,'gz_ObjectAccessField',[ 'fgroupid' =>$selectedLeftData['id']]);
    	}
    	if($in){
    		showMsg(0,'成功');
    	}
    	showMsg(1,'失败');
    }
    
    public function getaccessField(Request $request){
    	//fobjhide
    	$FItemID = $request ->get('id');//组id
    	if(empty($FItemID)){
    		returnData(1, '组名参数错误');
    	}
    	 
    	$in = SqlServerUtil::exec1($this->SqlServer,'select FFunc,FIndex, FObjectID,FObjectType ,name    from gz_ObjectAccessField where fgroupid ='.$FItemID );
    	showMsg(0,'成功',$in);
    }
    
    /**
    * U8 - 同步数据
    * @date: 2022年10月28日 下午5:33:04
    * @author: juyi
    */
    public function SyncData($cInvCode){
		//建立连接
    	$serverConnect  = $this->getDbConnect();
    	if(!$serverConnect){
    		showMsg(1,'失败', "ERP 数据库连接失败！" );
    	}
    	$result =['kucunQty'=>0,'kcPriceNofax'=>0,'zuixinCgPrice'=> 0 ];
    	// gz_YU8CB -- 拿到 库存数量，	库存单价-不含税	 ，最近的采购单价-不含税单价
    	//取 最新数据 最近的采购单价-不含税单价 iunitprice
    	$sql="select top 1 caudittime , cinvcode, itaxprice, iunitprice,inatunitprice
From zpurpoheader with(nolock) inner join zpurpotail with(nolock) on zpurpoheader.poid=zpurpotail.poid  
Where 1=1 and  cInvCode = '{$cInvCode}'  order by caudittime desc "; 
    	$res  = SqlServerUtil::execTosqlOK( $serverConnect ,$sql ,2);
    	if($res){
    		$result['zuixinCgPrice'] = $res['iunitprice'] ;
    	}
    	//库存数量
    	
    	
    	//库存单价 -- 结存库存单价
    	
    	
    	// 插入  --  gz_YU8CB
    	
    	showMsg(0,'成功',$res );
    	
    }
    
    
    private function getDbConnect(){
    	$DB =   env('DB_DATABASE_YCDB');
    	$serverConfig = [ "UID" => env("DB_USERNAME_YCDBUSER"), "PWD" => env("DB_PASSWORD_YCDBPASS"), "Database" => $DB];
    	$con =  sqlsrv_connect(env("DB_HOST_IP"), $serverConfig);
    	if($con){
    		return $con ;
    	}else{
//     		die( print_r( sqlsrv_errors()  , true));
    		return false ; 
    	}
    	
    }
    	
    /**
    * 分析报表 数据
    * @date: 2022年10月28日 下午5:39:55
    * @author: juyi
    */	
    public function fenxibbData(Request $request){
    	//gz_YU8CB 
    	 
    	
    	
    	showMsg(0,'成功' );
    	
    }
    
     /**
     * 字段获取
     * @date: 2022年11月2日 下午6:32:13
     * @author: juyi
     */ 
    public function vxetableConfig(Request $request){
    	$FRepKey = $request->get('FRepKey');
    	$opername = $request->get('opername'); //当前登录人名称      '测试3'
    	
    	$FRepPage = $request->get('FRepPage')??0 ;
    	$opernameStr = '';
    	$ConData =[];
    	$fieldData = [];
    	$removeData = [];
    	$FUnControlStr ='';
    	$FUnControl  = $request->FUnControl??0;
    	if ($FUnControl >= 0   ) {
    		$FUnControlStr="and ( FUnControl =  {$FUnControl} )";
    	} 
    	
    	if($FRepKey == '14002'){
    		$basesql="select * from gz_RepListTitle where FRepKey='{$FRepKey}' and FRepPage = '{$FRepPage}' and FRepHide = 0  {$FUnControlStr}  {$opernameStr} order by FRepIndex ";
    		$baseData = SqlServerUtil::execToSql($this->SqlServer, $basesql );
    		if($baseData){
    			$baseData = arraykeyToLower($baseData);
    			foreach ($baseData as $k=>$v)
    			{
    				$baseData[$k]['frepfld'] = strtolower($v['frepfld']);
    			}
    		}
    		returnData(0, '成功',$baseData);
    	}else{
	    	//字段权限 查看
	    	//判断是否在系统管理员组
	    	$conSql ="SELECT  ad.username,g.fname  from gz_user_group ug 
					left join  gz_admin ad   on ug.userid = ad.id 
					left join gz_group g  on  g.id = ug.groupid 
					where g.fname = '系统管理员组'  and  ad.username ='{$opername}' ";
	    	$ConData = SqlServerUtil::execToSql($this->SqlServer, $conSql );
	    	if(empty($ConData))
	    	{
	    		//不在 ，所在权限组 是否有权限查看
	    		$fieldSql ="SELECT  ad.username,g.fname ,fld.FFunc
			    		from gz_user_group ug
			    		left join  gz_admin ad   on ug.userid = ad.id
			    		left join gz_group g  on  g.id = ug.groupid
			    		left join gz_ObjectAccessField fld on fld.fgroupid = g.id
			    		where  ad.username ='{$opername}'";
	    		$fieldData = SqlServerUtil::execToSql($this->SqlServer, $fieldSql );
	    		$removeData = getFldViewDiff($fieldData);
	    	}
	//     	dd($removeData);
	    	//新增，修改 -- 显示 0 ，序时薄 ==0，1 
	    	//FRptTypeFlag --序时薄显示0 ，1-隐藏
	    	//FUnControl -- 新增修改0 ，1-隐藏
	    	//FRepMeg -- 下拉框1 ,单选框2 ,多选框3 ,日期框4 ,禁止编辑5 , 多文本框6
	    	$basesql="select * from gz_RepListTitle where FRepKey='{$FRepKey}' and FRepPage = '{$FRepPage}' and FRepHide = 0  {$FUnControlStr}  {$opernameStr} order by FRepIndex ";
	    	$baseData = SqlServerUtil::execToSql($this->SqlServer, $basesql );
	    	if($baseData){
	    		$baseData = arraykeyToLower($baseData);
	    		foreach ($baseData as $k=>$v)
	    		{
	    			$baseData[$k]['frepfld'] = strtolower($v['frepfld']);
	    		}
	    	}
	    	// 过滤权限
	    	if($removeData){
	    		foreach ($baseData as $k1=> $v1)
	    		{
	    			if(in_array($v1['frightkey'] ,$removeData)) {
	    				unset($baseData[$k1]);
	    			}
	    		}
	    		$baseData = array_values($baseData);
	    		
	    	}
	//     	dd($baseData);
	    	returnData(0, '成功',$baseData);
    	}
    }
    
  
    /**
    * vue=table -数据获取
    * @date: 2022年11月2日 下午6:32:17
    * @author: juyi
    */
    public function vxetableGenList(Request $request){
    	$page= $request ->get('page');
    	if(!isset($page)) $page =1;
    	$limit= $request ->get('pageSize');
    	if(!isset($limit)) $limit =10;
    	
    	$FRepKey = $request->FRepKey; // 26005--清单
    	$FRepPage  = $request->FRepPage??0 ; //这里0 -- 序时薄 ，1-单据
    	$fid =$request->fid??0;
    	$fidStr = "";
    	
    	$keywordStr ='';
    	$fstatusStr ='';
    	$timeStr='';
    	$fcategoryStr ='';
    	
    	if(in_array($FRepKey, ['26001' , '26002', '26003', '26004', '26005','26007' , '30001' , '30002', '30003', '40001', '40002', '40003', '50001'  ])  ){
    		if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
    			$keyword =  $request->keyword ;
    			$keywordStr=" and ( charindex('{$keyword}',v1.Fname)>0 )";
    		}
    		
    	}elseif(in_array($FRepKey, [ '26008', '26009', '26010'  , '26011', '26012', '26013' ,'26014', '26015', '26016', '26017' ,'26018', '26019', '26020'  ])  ){
    		if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
    			$keyword =  $request->keyword ;
    			$keywordStr=" and ( charindex('{$keyword}',v1.Fbrand)>0   or charindex('{$keyword}',v1.Fmodel)>0 )";
    		}
    		
    	} elseif(in_array($FRepKey, ['14002'  ])){
    		if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
    			$keyword =  $request->keyword ;
    			$keywordStr=" and (charindex('{$keyword}',v1.FCategory)>0 or charindex('{$keyword}',v1.FKey)>0 or charindex('{$keyword}',v1.FValue)>0 or charindex('{$keyword}',v1.FDescription)>0 or charindex('{$keyword}',v1.FExplanation)>0)";
    		}
    		
    		if ($request->has('fcategory') and $request->fcategory != '' and !empty($request->fcategory)) {
    			$fcategory = $request->fcategory ;
    			$fcategoryStr=" and v1.FCategory = '{$fcategory}' ";
    		}
    		
    		
    	}
    	
    	$fstatus = $request->fstatus?$request->fstatus:0;
    	if($fstatus == 1){
    		//未审核 1
    		$fstatusStr = " and v1.fstatus = 0";
    	}elseif($fstatus == 2){
    		//审核 2
    		$fstatusStr = " and v1.fstatus = 1";
    	}
    	
    	// 这里是 取  $fid
//     	if($fid>0){
//     		$fidStr = " and fid ={$fid}";
//     	}
//     	$sql=" select * from gz_Yqingdanf where 1=1 {$fidStr} ";
    	
    	$sqlData = getfileSql($FRepKey);
    	if(!$sqlData){
    		showMsg(1,'设置Sql不存在');
    	}
    	//替换
    	$sql= $sqlData ;
    	$vowels = array("\n", "\r", "\t");
    	$sql = str_replace($vowels, ' ',$sql);
    	
    	$sql = str_replace('{$keyword}', $keywordStr, $sql);
    	$sql = str_replace('{$fstatus}', $fstatusStr, $sql);
    	$sql = str_replace('{$timeStr}', $timeStr, $sql);
    	
    	$sql = str_replace('{$fcategoryStr}', $fcategoryStr, $sql);
    	
    	$newsql = $sql;
    	$sql=" select top $limit * from ( $sql ) temp_row where rownumber>(($page-1)*$limit)";
		//echo $sql;die; 
		// execTosqlOK 
    	$res = SqlServerUtil::execTosqlOK($this->SqlServer,  $sql) ; 
    	$getVexTableColumnData = $this->getVexTableColumn($FRepKey,$FRepPage ,-1) ;
    	if($res ){
    		$res = arraykeyToLower($res);
    		foreach ($res as $k =>&$v)
	    	{
	    		foreach ($getVexTableColumnData as $kc=>$vc)
	    		{
	    			if( ( empty($v[$vc['frepfld']]) || $v[$vc['frepfld']] =='0' ) && $vc['freptype'] == 131 ){
	    				$v[$vc['frepfld']] =0;
	    			}
	    			
	    			if( !empty($v[$vc['frepfld']]) && $v[$vc['frepfld']]>0  && $vc['freptype'] == 131 ){
	    				$v[$vc['frepfld']] =round($v[$vc['frepfld']],$vc['fdecplaces']);
	    			}
	    			
	    			if( empty($v[$vc['frepfld']])  && ($vc['freptype'] == 202 || $vc['freptype'] == 200 ) ){
	    				$v[$vc['frepfld']] = '';
	    			}
	    			$res[$k][$vc['frepfld']] = $v[$vc['frepfld']] ;
	    		}
	    	}
    	
    	}
    	
    	$datasql = substr( $newsql ,stripos($newsql ,' from')+5  );
    	
    	$datasql = iconv( 'UTF-8','GBK',$datasql);
    	
    	$countSql ="SELECT COUNT(1) AS total FROM  {$datasql} ";
    	$count = SqlServerUtil::exec($this->SqlServer, $countSql);
    	$total = !empty($count[0]['total']) ? $count[0]['total']:0;
    	$this->response['total'] = $total;
    	$this->response['pageSize'] = $limit;
    	$last_page = 0;
    	if($count && count($count)>0){
    		$last_page = !empty($total) ? ceil($total/$limit):0;
    	}
    	
    	$this->response['Data'] = $res;
    	$this->response['currentPage'] = $page;
    	$this->response['lastPage'] = $last_page;
    	return response()->json($this->response);
    	
    }
    
   
    /**
    * Vxe-table  -- 新增 ，保存  
    * @date: 2022年11月3日 下午2:36:56
    * @author: juyi
    */
    public function vxetableGenAdd(Request $request){
    	$FRepKey= $request->get('FRepKey');
    	$db = columnBiao($FRepKey);//表名
    	$opername  = $request->opername?$request->opername:'' ;
    	$FRepPage  = $request->FRepPage??0 ; //这里0 -- 序时薄 ，1-单据
    	
    	$data =  $request->all() ;
    	$getVexTableColumnData = $this->getVexTableColumn($FRepKey , $FRepPage) ;
    	//判断用户权限 是否有修改
    	
    	//判断是否在系统管理员组
    	$conSql ="SELECT  ad.username,g.fname  from gz_user_group ug
    	left join  gz_admin ad   on ug.userid = ad.id
    	left join gz_group g  on  g.id = ug.groupid
    	where g.fname = '系统管理员组'  and  ad.username ='{$opername}' ";
    	$ConData = SqlServerUtil::execToSql($this->SqlServer, $conSql  );
    	
    	if(empty($ConData))
    	{
    		$sql = "SELECT ad.username,g.fname,g.id ,ag.FAccessMask from gz_user_group ug 
				left join gz_admin ad   on ug.userid = ad.id 
				left join gz_group g  on  g.id = ug.groupid 
			    left join gz_accesscontrol_group ag on ag.fuserid=ug.groupid  and FObjectID = '{$FRepKey}'
				where ad.username = '{$opername}' ";
    		$res2 = SqlServerUtil::execTosql($this->SqlServer, $sql,2);
    		$FAccessMask = 8;
    		if($res2){
    			$FAccessMaskV = $res2['FAccessMask'];
    			if (($FAccessMaskV & $FAccessMask) != $FAccessMask) { //用户自身具备权限
    				showMsg(400,'此用户没有修改权限');
    			}
    		}else{
    			showMsg(400,'此用户没有修改权限');
    		}
    	}
    	
    	//配置信息 参数
    	$fsetchaiyouprice = 0;
    	$fsetqigangprice = 0;
    	$fsetranqiprice = 0;
    	$fsetzhuhunyouprice = 0;
    	$fsethuilv = 1;
//     	if(in_array($FRepKey, ['26005','26007','26003'])){
//     		//专利  -- 汇率 FSetHuiLv
//     		$getSystemProfile = $this->getSystemProfile();
//     		 // fkey in ('fsetchaiyouprice' , 'fsetqigangprice' ,'fsetranqiprice' ,'fsetzhuhunyouprice','fsethuilv' )");
//     		// 油气费 26003 ， 26007 非  -- 单价  
    		
    		
//     	}
    	
		// 新增 -- insertRecords, 
    	$insertRecords = isset($data['insertRecords'])?$data['insertRecords'] :[];
    	if(!empty($insertRecords)){
    		$insData=[];
    		foreach ($insertRecords as $k =>&$v)
    		{
    			foreach ($getVexTableColumnData as $kc=>$vc)
    			{
    				if( ( empty($v[$vc['frepfld']]) || $v[$vc['frepfld']] =='.00' ) && $vc['freptype'] == 131 ){
    					$v[$vc['frepfld']] =0;
    				}
    				
    				if( empty($v[$vc['frepfld']])  && ($vc['freptype'] == 202 || $vc['freptype'] == 200 ) ){
    					$v[$vc['frepfld']] = '';
    				}
    				$insData[$k][$vc['frepfld']] = $v[$vc['frepfld']] ; 
    			}
    			//加清单
    			if($FRepKey == '26005'){
    				$insData[$k]['famount'] = $v['fqty'] * $v['fprice'] ;
    	 		}
    	 		//气油费
    	 		if($FRepKey == '26003'){
    	 			//气缸油单价 
    	 			$insData['fcylinderoilprice'] =  ($insData['fcylinderoilprice']??0)  ;
    	 			//油 气  合计
    	 			$insData['fallamount'] = (($insData['fdieseloilqty']??0) * ($insData['fprice']??0)) + (($insData['fcylinderoil']??0) * $insData['fcylinderoilprice']) + (($insData['fmainoil']??0) * $insData['fmainoilprice']) + (($insData['fgasqty']??0) * ($insData['fgasprice']??0 ) );
    	 		}
    	 		//专利合计
    	 		if($FRepKey == '26004'){
    	 			$insData['fpatentfeeamount'] =  ($insData['fexchangerate']??1) * ($insData['fpatentfee']??0 ) ;
    	 		}
    	 		$insData['fcreatemanager'] = $opername;
//     	 		//辅材成本 26008
//     	 		if($FRepKey == 26008){
//     	 			$insData['fallamount'] =  ($insData['fhjcj']??0) + ($insData['fjgcj']??0 ) + ($insData['fzscj']??0 ) ;
//     	 		}
    			 
    		} 
    		
//     		dd($insData);
    	
    		SqlServerUtil::sqlsrvAllTosql($this->SqlServer ,$db , $insData);
    		$this->writeLog(getMkName($FRepKey),'新增' , $FRepKey , $insData ,$opername );
    	}
    	// 修改 --  updateRecords, 
    	$updateRecords = isset( $data['updateRecords'])?$data['updateRecords'] :[];
 		$fidField = 'fid';
 		if(in_array($FRepKey, ['14002'])){
 			$fidField = 'fitemid';
 		} 
 	
    	if(!empty($updateRecords)){
    		foreach ($updateRecords as $kup=>&$vup)
    		{
    			$insData =[];
    			$where= [];
    			 
    			$where[$fidField] = $vup[$fidField];
    		 
    			foreach ($getVexTableColumnData as  $up)
    			{
    				if( ( empty($vup[$up['frepfld']]) || $vup[$up['frepfld']] =='.00' ) && $up['freptype'] == 131 ){
    					$vup[$up['frepfld']] =0;
    				}
    				
    				if( empty($vup[$up['frepfld']])  && ($up['freptype'] == 202 || $up['freptype'] == 200 ) ){
    					$vup[$up['frepfld']] = '';
    				}
    				
    				$insData[$up['frepfld']] = $vup[$up['frepfld']] ;
    			 
    				//加清单
    				if($FRepKey == '26005'){
    					$insData['famount'] = $vup['fqty'] * $vup['fprice'] ;
    				}
    				//加清单
//     				if($FRepKey == '26005'){
//     					$insData[$k]['famount'] = $v['fqty'] * $v['fprice'] ;
//     				}
    				//气油费
    				if($FRepKey == '26003'){
    					//气缸油单价*1.058
    					$insData['fcylinderoilprice'] =  ($insData['fcylinderoilprice']??0)  ;
    					//油 气  合计
    					$insData['fallamount'] = (($insData['fdieseloilqty']??0) * ($insData['fprice']??0)) + (($insData['fcylinderoil']??0) * $insData['fcylinderoilprice']) + (($insData['fmainoil']??0) * $insData['fmainoilprice']) + (($insData['fgasqty']??0) * ($insData['fgasprice']??0 ) );
    				}
    				//专利合计
    				if($FRepKey == '26004'){
    					$insData['fpatentfeeamount'] =  ($insData['fexchangerate']??1) * ($insData['fpatentfee']??0 ) ;
    				}
    				
    				
    			}
    			
    			SqlServerUtil::exeupdateTosql($this->SqlServer,$db,$insData,$where);
    			$this->writeLog(getMkName($FRepKey),'修改' , $FRepKey , $insData ,$opername );
    		}
    		
    	}
		//删除 --  removeRecords 
    	$removeRecords = isset( $data['removeRecords'])?$data['removeRecords'] :[];  
    	if(!empty($removeRecords)){
			$Fids =[];
			$Fids = join("','", array_column($removeRecords, 'fid'));
// 			dd($Fids);
			SqlServerUtil::sqlsrvDelete($this->SqlServer,$db, ['fid'=>"'".$Fids ."'" ],true);
    		$this->writeLog(getMkName($FRepKey),'删除' , $FRepKey , $removeRecords ,$opername );
    	}
    	showMsg(0,'成功' );
    }
    
    
    
    
    
    
    /**
    * 文件用途描述 famountnotaxnodis
    * @date: 2022年11月4日 下午2:50:23
    * @author: juyi
    */ 
    public function vxetableGenAddSingle(Request $request){
    	$FRepKey= $request->get('FRepKey');
    	$fid= $request->get('fid')??0;
    	$db = columnBiao($FRepKey);//表名
    	$opername  = $request->opername?$request->opername:'' ;
    	$FRepPage  = $request->FRepPage??0 ; //这里0 -- 序时薄 ，1-单据
    	$data =  $request->all() ;
//     	dd($data);
    	$getVexTableColumnData = $this->getVexTableColumn($FRepKey , $FRepPage) ;
    	// 新增 -- insertRecords,这里 修改有 fid 值
    	$insertRecords = $data['updateRecords'];
    	if(!empty($insertRecords)){
    		if($fid>0)
    		{
    			// 修改	
    			foreach ($insertRecords as $kup=>&$vup)
    			{
    				$insData =[];
    				$where = [];
    				$where = ['fid'=>$vup['fid']];
    				foreach ($getVexTableColumnData as  $up)
    				{
    					if( ( empty($vup[$up['frepfld']]) || $vup[$up['frepfld']] =='.00' ) && $up['freptype'] == 131 ){
    						$vup[$up['frepfld']] =0;
    					}
    					
    					if( empty($vup[$up['frepfld']])  && ($up['freptype'] == 202 || $up['freptype'] == 200 ) ){
    						$vup[$up['frepfld']] = '';
    					}
    					
    					$insData[$up['frepfld']] = $vup[$up['frepfld']] ;
    					
    					//加清单
    					if($FRepKey == '26005'){
    						$insData['famount'] = $vup['fqty'] * $vup['fprice'] ;
    					}
    				}
//     				dd($insData);
    				SqlServerUtil::exeupdateTosql($this->SqlServer,$db,$insData,$where);
    				$this->writeLog(getMkName($FRepKey),'修改' , $FRepKey , $insData ,$opername );
    			}
    			 
    		}else{
    			// 新增	
	    		$insData=[];
	    		foreach ($insertRecords as $k =>&$v)
	    		{
	    			foreach ($getVexTableColumnData as $kc=>$vc)
	    			{
	    				if( ( empty($v[$vc['frepfld']]) || $v[$vc['frepfld']] =='.00' ) && $vc['freptype'] == 131 ){
	    					$v[$vc['frepfld']] =0;
	    				}
	    				
	    				if( empty($v[$vc['frepfld']])  && ($vc['freptype'] == 202 || $vc['freptype'] == 200 ) ){
	    					$v[$vc['frepfld']] = '';
	    				}
	    				$insData[$k][$vc['frepfld']] = $v[$vc['frepfld']] ;
	    			}
	    			//加清单
	    			if($FRepKey == '26005'){
	    				$insData[$k]['famount'] = $v['fqty'] * $v['fprice'] ;
	    			}
	    			
	    			
	    		}
	    		
	    		SqlServerUtil::sqlsrvAllTosql($this->SqlServer ,$db , $insData);
	    		$this->writeLog(getMkName($FRepKey),'新增' , $FRepKey , $insData ,$opername );
    		}
    	}
     
    	
    	showMsg(0,'成功' );
    	
    }
    
    
    
    //使用测试  --序时薄
    public function XsbList(Request $request){
    	$page= $request ->get('page');
    	if(!isset($page)) $page =1;
    	$limit= $request ->get('pageSize');
    	if(!isset($limit)) $limit =10;
    	
    	$FRepKey = $request->FRepKey; // 26005--清单
    	$FRepPage  = $request->FRepPage??0 ; //这里0 -- 序时薄 ，1-单据
    	$fid =$request->fid??0;
    	$fidStr = "";
    	
    	$keywordStr ='';
    	$fstatusStr ='';
    	$timeStr='';
    	
    	if(in_array($FRepKey, ['26001' , '26002', '26003', '26004', '26005','26007' , '30001' , '30002', '30003', '40001', '40002', '40003', '50001' ])  ){
    		if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
    			$keyword =  $request->keyword ;
    			$keywordStr=" and ( charindex('{$keyword}',v1.Fname)>0 )";
    		}
    		
    	}elseif(in_array($FRepKey, [ '26008', '26009', '26010'  ])  ){
    		if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
    			$keyword =  $request->keyword ;
    			$keywordStr=" and ( charindex('{$keyword}',v1.Fbrand)>0   or charindex('{$keyword}',v1.Fmodel)>0 )";
    		}
    		
    	}elseif(in_array($FRepKey, [ '26006' ])  ){
    		if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
    			$keyword =  $request->keyword ;
    			$keywordStr=" and ( charindex('{$keyword}',v1.Fbillno)>0   )";
    		}
    	}
    	
    	$fstatus = $request->fstatus?$request->fstatus:0;
    	if($fstatus == 1){
    		//未审核 1
    		$fstatusStr = " and v1.fstatus = 0";
    	}elseif($fstatus == 2){
    		//审核 2
    		$fstatusStr = " and v1.fstatus = 1";
    	}
    	$sqlData = getfileSql($FRepKey);
    	if(!$sqlData){
    		showMsg(1,'设置Sql不存在');
    	}
    	//替换
    	$sql= $sqlData ;
    	$vowels = array("\n", "\r", "\t");
    	$sql = str_replace($vowels, ' ',$sql);
    	
    	$sql = str_replace('{$keyword}', $keywordStr, $sql);
    	$sql = str_replace('{$fstatus}', $fstatusStr, $sql);
    	$sql = str_replace('{$timeStr}', $timeStr, $sql);
    	
    	$newsql = $sql;
    	$sql=" select top $limit * from ( $sql ) temp_row where rownumber>(($page-1)*$limit)";
//     	    	echo $sql;die;
    	$res = SqlServerUtil::execTosqlOK($this->SqlServer,  $sql) ;
    	
    	$getVexTableColumnData = $this->getVexTableColumn($FRepKey,$FRepPage ,-1) ;
 
    	if($res ){
    		$res = arraykeyToLower($res);
    		foreach ($res as $k =>&$v)
    		{
    			foreach ($getVexTableColumnData as $kc=>$vc)
    			{
    				if( ( empty($v[$vc['frepfld']]) || $v[$vc['frepfld']] =='0' ) && $vc['freptype'] == 131 ){
    					$v[$vc['frepfld']] =0;
    				}
    				
    				if( !empty($v[$vc['frepfld']]) && $v[$vc['frepfld']]>0  && $vc['freptype'] == 131 ){
    					$v[$vc['frepfld']] = round($v[$vc['frepfld']],$vc['fdecplaces']);
    				}
    				
    				if( empty($v[$vc['frepfld']])  && ($vc['freptype'] == 202 || $vc['freptype'] == 200 ) ){
    					$v[$vc['frepfld']] = '';
    				}
    				$res[$k][$vc['frepfld']] = $v[$vc['frepfld']] ;
    			}
    		}
    		
    	}
    	 
    	$datasql = substr( $newsql ,stripos($newsql ,' from')+5  );
    	
    	$datasql = iconv( 'UTF-8','GBK',$datasql);
    	
    	$countSql ="SELECT COUNT(1) AS total FROM  {$datasql} ";
    	$count = SqlServerUtil::exec($this->SqlServer, $countSql);
    	$total = !empty($count[0]['total']) ? $count[0]['total']:0;
    	$this->response['total'] = $total;
    	$this->response['pageSize'] = $limit;
    	$last_page = 0;
    	if($count && count($count)>0){
    		$last_page = !empty($total) ? ceil($total/$limit):0;
    	}
    	
    	$this->response['Data'] = $res;
    	$this->response['currentPage'] = $page;
    	$this->response['lastPage'] = $last_page;
    	return response()->json($this->response);
    	
    }
    
    
    //单据 =-- 字段 
    public function vxetableBillConfig(Request $request){
    	$FRepKey = $request->get('FRepKey');
    	$opername = $request->get('opername'); //当前登录人名称      '测试3'
    	
    	$FRepPage = $request->get('FRepPage')??0 ;
    	$opernameStr = '';
    	$ConData =[];
    	$fieldData = [];
    	$removeData = [];
    	//新增，修改 -- 显示 0 ，序时薄 ==0，1
    	//FRptTypeFlag --序时薄显示0 ，1-隐藏
    	//FUnControl -- 新增修改0 ，1-隐藏
    	//FRepMeg -- 下拉框1 ,单选框2 ,多选框3 ,日期框4 ,禁止编辑5 , 多文本框6
    	$FUnControlStr ='';
    	$FUnControl  = $request->FUnControl??0;
    	if ($FUnControl >= 0   ) {
    		$FUnControlStr="and ( FUnControl =  {$FUnControl} )";
    	}
    	if($FRepKey == '3001002'){
    		$basesql="select * from gz_RepBillTitle where FRepKey='{$FRepKey}' and FRepPage = '{$FRepPage}' and FRepHide = 0  {$FUnControlStr} order by FRepIndex ";
    		$baseData = SqlServerUtil::execToSql($this->SqlServer, $basesql );
    		if($baseData){
    			$baseData = arraykeyToLower($baseData);
    			foreach ($baseData as $k=>$v)
    			{
    				$baseData[$k]['frepfld'] = strtolower($v['frepfld']);
    			}
    		}
    		returnData(0, '成功',$baseData);
    	}else{
	    	//字段权限 查看
	    	//判断是否在系统管理员组
	    	$conSql ="SELECT  ad.username,g.fname  from gz_user_group ug
	    	left join  gz_admin ad   on ug.userid = ad.id
	    	left join gz_group g  on  g.id = ug.groupid
	    	where g.fname = '系统管理员组'  and  ad.username ='{$opername}' ";
	    	$ConData = SqlServerUtil::execToSql($this->SqlServer, $conSql );
	    	if(empty($ConData))
	    	{
	    		//不在 ，所在权限组 是否有权限查看
	    		$fieldSql ="SELECT  ad.username,g.fname ,fld.FFunc
	    		from gz_user_group ug
	    		left join  gz_admin ad   on ug.userid = ad.id
	    		left join gz_group g  on  g.id = ug.groupid
	    		left join gz_ObjectAccessField fld on fld.fgroupid = g.id
	    		where  ad.username ='{$opername}'";
	    		$fieldData = SqlServerUtil::execToSql($this->SqlServer, $fieldSql );
	    		$removeData = getFldViewDiff($fieldData);
	    	}
	    	
	    	
	    	$basesql="select * from gz_RepBillTitle where FRepKey='{$FRepKey}' and FRepPage = '{$FRepPage}' and FRepHide = 0  {$FUnControlStr}  {$opernameStr} order by FRepIndex ";
	//     	echo $basesql;die;
	    	$baseData = SqlServerUtil::execToSql($this->SqlServer, $basesql );
	    	if($baseData){
	    		$baseData = arraykeyToLower($baseData);
	    		foreach ($baseData as $k=>$v)
	    		{
	    			$baseData[$k]['frepfld'] = strtolower($v['frepfld']);
	    		}
	    	}
	    	// 过滤权限
	    	if($removeData){
	    		foreach ($baseData as $k1=> $v1)
	    		{
	    			if(in_array($v1['frightkey'] ,$removeData)) {
	    				unset($baseData[$k1]);
	    			}
	    		}
	    		$baseData = array_values($baseData);
	    		
	    	}
	    	returnData(0, '成功',$baseData);
    	}
    }
    
    
    /**
    * 单据保存
    * @date: 2022年12月16日 上午10:43:28
    * @author: juyi
    */
    public function billGenAdd(Request $request){
    	$FRepKey= $request->get('FRepKey');
    	$db = columnBiao($FRepKey);//表名
    	$opername  = $request->opername?$request->opername:'' ;
    	$FRepPage  = $request->FRepPage??0 ; //这里0 -- 序时薄 ，1-单据
    	if($FRepPage == 1 ){
    		$db = columnBiao($FRepKey.'_1' );//表名
    	}
    	$data =  $request->all() ;
    	$getVexTableColumnData = $this->getVexBillColumn($FRepKey  ) ;
    	$fisrqr =  $request->fisrqr??0 ;  //再次确认情况 
    	$resMX = [];
//     	dd($request->all()); 
    	//判断用户权限 是否有修改
    	//判断是否在系统管理员组
//     	$conSql ="SELECT  ad.username,g.fname  from gz_user_group ug
//     	left join  gz_admin ad   on ug.userid = ad.id
//     	left join gz_group g  on  g.id = ug.groupid
//     	where g.fname = '系统管理员组'  and  ad.username ='{$opername}' ";
//     	$ConData = SqlServerUtil::execToSql($this->SqlServer, $conSql  );
    	
//     	if(empty($ConData))
//     	{
//     		$sql = "SELECT ad.username,g.fname,g.id ,ag.FAccessMask from gz_user_group ug
//     		left join gz_admin ad   on ug.userid = ad.id
//     		left join gz_group g  on  g.id = ug.groupid
//     		left join gz_accesscontrol_group ag on ag.fuserid=ug.groupid  and FObjectID = '{$FRepKey}'
//     		where ad.username = '{$opername}' ";
//     		$res2 = SqlServerUtil::execTosql($this->SqlServer, $sql,2);
//     		$FAccessMask = 8;
//     		if($res2){
//     			$FAccessMaskV = $res2['FAccessMask'];
//     			if (($FAccessMaskV & $FAccessMask) != $FAccessMask) { //用户自身具备权限
//     				showMsg(400,'此用户没有修改权限');
//     			}
//     		}else{
//     			showMsg(400,'此用户没有修改权限');
//     		}
//     	}
		$fidField ='fid';
    	// 新增 -- insertRecords,
    	$insertRecords = isset($data['insertRecords'])?$data['insertRecords'] :[];
    	
    	$updateRecords = isset( $data['updateRecords'])?$data['updateRecords'] :[];
    	
    	
    	//判断技术中心数据录入  14007 , 生产部数据录入  14010
    	if(in_array($FRepKey, [ '14007','14010'] )) {
    		
    		if( empty($insertRecords) &&  empty($updateRecords) ){
    			showMsg(1,'请输入必要字段（机型）' );
    		}
    		if(!empty($insertRecords)){
    			$fmodel =join("','", array_column($insertRecords, 'fmodel'));
    			$fmodelStr = "'".$fmodel ."'";
    			$a1 = " select fmodel from {$db} where fmodel in ({$fmodelStr}) ";
    			$aTemp = SqlServerUtil::execTosql($this->SqlServer, $a1 );
    			foreach ($insertRecords as &$v)
    			{
    				if(!isset($v['fid'])){
    					if( $aTemp ){
    						showMsg(1,'输入机型 已存在, '.join("','",array_column($aTemp,'fmodel')) );
    					}
    				}
    			}
    		}
    		
    	}elseif(in_array($FRepKey, [ '14009'] )){
    		//业务需求(市场部)   14009
    		if( empty($insertRecords) &&  empty($updateRecords) ){
    			showMsg(1,'请输入必要字段（机型）' );
    		}
    		//业务
    		//判断 WINGD和 MAN
    		//业务优惠金额 不得超过 专利收费标准金额
    		if( !empty($insertRecords)){
    			//设计功率  
    			//专利费
    			$ZlData = SqlServerUtil::execToSql($this->SqlServer, "select * from gz_Yzhuanlif " );
    			foreach ($insertRecords as $ks =>$vs)  {
    				$brand = SqlServerUtil::execTosql($this->SqlServer, "select fbrand,fpower  from gz_YBaseJS where fmodel ='{$vs['fmodel']}'",2 ); 
    				if(empty($brand)){
    					showMsg(400,'请检验机型，是否正确');
    				}
    				//判断是否是甲醇机
    				//1甲醇机项目在市场部需求环节，是否含EGR，选择不能为否。且加账清单需要有EGR或者ECOEGR
//     				if( stripos( strtoupper($vs['fmodel']) , 'LGIM' ) !== false)    {
//     					if(  $vs['fisegr'] == '否'  ){
//     						showMsg(400, '甲醇机: '.$vs['fmodel'].' , 是否含EGR选择不能为否，请查看');
//     					}
//     				}
    				
    				if($vs['fegcmodel'] !='无'){
    					$icerdbsql = " select v1.* from  gz_YjzICERDB v1 where  v1.fEGCModel = '{$vs['fegcmodel']}'  " ;
    					$resICERDBJS = SqlServerUtil::execToSql($this->SqlServer, $icerdbsql,2 );
    					if(empty($resICERDBJS)){
    						showMsg(400, 'EGC型号: '.$vs['fegcmodel'].' , 不存在，请检查。');
    					}
    				}
    				
    				//常规机不能是 燃油或燃气 版 
    				if( fisDFRanYou($vs['fmodel'],$vs['fisryrq'])){
    					showMsg(400,'请检验机型是否是双料机，您选择 是：'.$vs['fisryrq']);
    				}
//     				dd($fisrqr,$fisrqr !=0 ,$brand['fpower']  ,$vs['fsjpower'] ,$brand['fpower']  !=$vs['fsjpower'] );
    				if($fisrqr ==0){
    					if($brand['fpower']  != $vs['fsjpower'] ){
    						showMsg(14009,'请检验是否和技术中心功率保持一致！');
    					}
    				} 
    				 
//     				dd($fisrqr ,$brand['fpower']  ,$vs['fsjpower'] ,$brand['fpower']  !=$vs['fsjpower'] );
    				
    				$tt = getZLValueYS($ZlData, $vs['fmodel'],$brand['fbrand']);
//     				dd($tt , $vs['fmodel'],$brand['fbrand']);
    				if($tt){
    					if($vs['fzlyhamount'] > $tt['fPatentfee'] ){
    						showMsg(400,'业务优惠金额 不得超过 专利收费标准金额');
    					 }
    				}
    			}
    			
    		}
    				
    				
    	}elseif(in_array($FRepKey, [ '26024',] )) {
    		//只针对 设置检验-- 船检费 参数  
    		//dd($insertRecords); --
    		
    	}elseif(in_array($FRepKey, [  '27001','27002','27003','27004','27005','27006','27007','27008','27009', ] )) {
    		if( empty($insertRecords) &&  empty($updateRecords) ){
    			showMsg(1,'请输入必要字段（机型 ）' );
    		}
    		if(!empty($insertRecords)){
    			$fmodel =join("','", array_column($insertRecords, 'fmodel'));
    			$fmodelStr = "'".$fmodel ."'";
    			
    			$a1 = " select fmodel from {$db} where fmodel in ({$fmodelStr}) ";
    			$aTemp = SqlServerUtil::execTosql($this->SqlServer, $a1 );
    			if( $aTemp ){
    				showMsg(1,'输入机型 已存在, '.join("','",array_column($aTemp,'fmodel')) );
    			 }
    			
    		}
    		
    	}elseif(in_array($FRepKey, [   '27010', '27011' ] )) {
    		if( empty($insertRecords) &&  empty($updateRecords) ){
    			showMsg(1,'请输入必要字段（机型 ）' );
    		}
    		
    		if(!empty($insertRecords)){
    			$fegcmodel =join("','", array_column($insertRecords, 'fegcmodel'));
    			$fegcmodelStr = "'".$fegcmodel ."'";
    			$a1 = " select fegcmodel from {$db} where fegcmodel in ({$fegcmodelStr}) ";
    			$aTemp = SqlServerUtil::execTosql($this->SqlServer, $a1 );
    			foreach ($insertRecords as &$v)
    			{
    				if(!isset($v['fid'])){
    					if( $aTemp ){
    						showMsg(1,'输入型号 已存在 , '.join("','",array_column($aTemp,'fegcmodel')).'请检查' );
    					}
    				}
    			}
    		}
    		
    	}else{
    		if( empty($insertRecords) &&  empty($updateRecords) ){
    			showMsg(1,'请输入必要字段（机型 ）' );
    		}
    	}
    	
    	//新增 === 
    	if(!empty($insertRecords)){
    		$insData=[];
    		foreach ($insertRecords as $k =>&$v)
    		{
    			$where= [];
    			if(isset($v['fid']) ) {
    				$where[$fidField] = $v[$fidField];
    			}
    			foreach ($getVexTableColumnData as $kc=>$vc)
    			{
    				if( ( empty($v[$vc['frepfld']]) || $v[$vc['frepfld']] =='.00' ) && $vc['freptype'] == 131 ){
    					$v[$vc['frepfld']] =0;
    				}
    				
    				if( empty($v[$vc['frepfld']])  && ($vc['freptype'] == 202 || $vc['freptype'] == 200 ) ){
    					$v[$vc['frepfld']] = '';
    				}
    				$insData[$k][$vc['frepfld']] = $v[$vc['frepfld']] ;
    				$insData[$k]['fcreatetime'] = getCurrentTime();
    				
    				if($FRepKey == '14009' || $FRepKey == '14011' || $FRepKey == '14012' || $FRepKey == '14013' ){
    					$insData[$k]['jiazhangdata'] = isset($v['jiazhangdata'])?$v['jiazhangdata']:[] ;
    				}
    				
    				if(in_array($FRepKey,['14010' ,'14007'])  ){
    					$resMX[$k]['opertype'] = '新增/修改' ;
    					$resMX[$k]['opername'] = $opername;
    					$resMX[$k][$vc['frepfld']] = $v[$vc['frepfld']] ;
    				}
    				
    				 
    			}
    			 
    			//市场部需求 14009
    			$aaTmp =[];
    			if($FRepKey == 14009){
    				$aaTmp = explode('+', $v['fsxtaishu'])   ;
    				// fsxtaishu
    				$insData[$k]['fqty'] =  intval(array_shift( $aaTmp ))   ;
    				//生成序列号
    				if(!isset($v['fid']) ) {
    					$insData[$k]['fbillno'] =  $this->getDanHao($FRepKey);
    				}
    			}
    			
    		}
//     		dd($v ,$insData ,7777);
    		if(isset($v['fid']) ) {//修改
				foreach ($insData as $kgen =>&$vgen)
				{
					if($FRepKey == '14009' || $FRepKey == '14011' || $FRepKey == '14012' || $FRepKey == '14013' ){
						if($vgen['jiazhangdata']){
							$vgen['jiazhangdatastr'] = join(",", array_column($vgen['jiazhangdata'], 'fid'));
							//gz_YjiazhangcbfMX
							$jzTEmp = [];
							foreach ($vgen['jiazhangdata'] as $kt =>$kv)
							{
								$jzTEmp[$kt]['fbrand'] = $kv['fbrand'] ;
								$jzTEmp[$kt]['fcode'] = $kv['fcode'] ;
								$jzTEmp[$kt]['fprodno'] = $vgen['fmodel'] ;
								$jzTEmp[$kt]['fallamount'] = $kv['ffaxamount'] ;
							}
// 							SqlServerUtil::sqlsrvAllTosql($this->SqlServer ,'gz_YjiazhangcbfMX' , $jzTEmp);
// 							SqlServerUtil::sqlsrvDelete($this->SqlServer ,'gz_Yjiazhangcbf' ,['fprodno'=>$vgen['fmodel']] );
							
// 							SqlServerUtil::sqlsrvAllTosql($this->SqlServer ,'gz_Yjiazhangcbf' , $jzTEmp);
							
							unset($vgen['jiazhangdata']);
						}else{
							unset($vgen['jiazhangdata']);
						}
						
					}
					if($FRepKey == '25007' ){
						//生效台数 
						$sxData = SqlServerUtil::execTosql($this->SqlServer, "select fqty  from gz_YBaseSC where fbillno ='{$vgen['fjybjbillno']}'",2 );
						$sxQty = $sxData['fqty'];
						
						$vgen['fcreatetime'] = getCurrentTime();
						$vgen['flutuf'] = $vgen['flvtuf']+ $vgen['fjizuojijiaf']+ $vgen['fzhusuf'] + $vgen['franyouf']+ $vgen['fguoluf'];
						$vgen['fquedingbf'] = $vgen['fzhengshuf'] + $vgen['flutuf'];
						// (整机检验费*汇率 +确定部分)+（母型机NOX排放*1+子型机NOX排放*（生效台数-1））/生效台数 
						$vgen['fallamount'] = round($vgen['fzjjianyanf']+$vgen['fquedingbf'] + ($vgen['fpaifangmuxing'] + $vgen['fpaifangzixing']*($sxQty- 1))/$sxQty ,2) ;
				
						SqlServerUtil::sqlsrvCreate($this->SqlServer,$db.'MX',$vgen );
					
					}
					
					SqlServerUtil::exeupdateTosql($this->SqlServer,$db,$vgen,$where);
					//生产部列表 14010
					if( in_array($FRepKey, ['14010' ]) ){
						$cs = $this->getSystemProfile(['FSetSendSMS'   ]);
						$this->genSendSms($cs['fsetsendsms'],getMkName($FRepKey).' ，机型为 ' .$vgen['fmodel'].'已做修改');
					}
				}
    			
    			$this->writeLog(getMkName($FRepKey),'修改' , $FRepKey , $insData ,$opername );
    		}else{
    			//新增 
    			$Cs = $this->getSystemProfile([ 'FSetFFAX',    ]);
    			foreach ($insData as $kgen =>&$vgen)
    			{
    				if($FRepKey == 27010){
    					$vgen['fcreatetime']= getCurrentTime();
    					$vgen['fguanlu'] = 0;
    					$vgen['ficerkzg'] = 0;
    					$vgen['fpengzhangjie3'] = 0;
    					$vgen['fpengzhangjie'] = 0;
    					$vgen['fbpvbeiya'] = 0;
    					$vgen['fsovjiezhifa'] = 0;
    					$vgen['ffrvliuliang'] = 0;
    					$vgen['fcbvfuiqi'] = 0;
    					$vgen['fsovjiezhifa'] = 0;
    					
    					$vgen['ffrvliuliang'] = 0;
    					$vgen['fcbvfuiqi'] = 0;
    					$vgen['fyalicgq16'] = 0;
    					$vgen['fwenducgq16'] = 0;
    					$vgen['fyalibiao12'] = 0;
    					$vgen['fwenduji12'] = 0 ;
    					$a1 = " select fguanlu,ficerkzg,fpengzhangjie3,fpengzhangjie,fbpvbeiya,fsovjiezhifa,
    					ffrvliuliang,fcbvfuiqi,fsovjiezhifa,ffrvliuliang,fcbvfuiqi,fyalicgq16,
    					fwenducgq16,fyalibiao12,fwenduji12 from {$db} where fegcmodel = {$vgen['fegcmodel']} ";
    					$JSTemp = SqlServerUtil::execTosql($this->SqlServer, $a1 ,2);
    					if($JSTemp){
    						$vgen['fguanlu'] = $JSTemp['fguanlu'];
    						$vgen['ficerkzg'] = $JSTemp['ficerkzg'];
    						$vgen['fpengzhangjie3'] = $JSTemp['fpengzhangjie3'];
    						$vgen['fpengzhangjie'] = $JSTemp['fpengzhangjie'];
    						$vgen['fbpvbeiya'] = $JSTemp['fbpvbeiya'];
    						$vgen['fsovjiezhifa'] = $JSTemp['fsovjiezhifa'];
    						$vgen['ffrvliuliang'] = $JSTemp['ffrvliuliang'];
    						$vgen['fcbvfuiqi'] = $JSTemp['fcbvfuiqi'];
    						$vgen['fsovjiezhifa'] = $JSTemp['fsovjiezhifa'];
    						
    						$vgen['ffrvliuliang'] = $JSTemp['ffrvliuliang'];
    						$vgen['fcbvfuiqi'] = $JSTemp['fcbvfuiqi'];
    						$vgen['fyalicgq16'] = $JSTemp['fyalicgq16'];
    						$vgen['fwenducgq16'] = $JSTemp['fwenducgq16'];
    						$vgen['fyalibiao12'] = $JSTemp['fyalibiao12'];
    						$vgen['fwenduji12'] = $JSTemp['fwenduji12'];
    					}
    					$vgen['fallamount'] = ($vgen['fguanlu']+$vgen['ficerkzg']+$vgen['fpengzhangjie3']
    							+$vgen['fpengzhangjie']+$vgen['fbpvbeiya']+$vgen['fsovjiezhifa']
    							+$vgen['ffrvliuliang']+$vgen['fcbvfuiqi']+ $vgen['fyalicgq16']
    							+$vgen['fwenducgq16']+$vgen['fyalibiao12']+$vgen['fwenduji12']
    							+($vgen['ficerewfy'] + $vgen['ficerylfy'])*(1+$Cs['fsetffax']/100) );
    					
    				}
    				if($FRepKey == 27011){
    					$vgen['fcreatetimecg']= getCurrentTime();
    					$vgen['ficerewfy'] = 0;
    					$vgen['ficerylfy'] = 0;
    					$a1 = " select ficerewfy,ficerylfy  from {$db} where fegcmodel = {$vgen['fegcmodel']} ";
    					$CGTemp = SqlServerUtil::execTosql($this->SqlServer, $a1 ,2);
    					if($CGTemp){
    						$vgen['ficerewfy'] = $CGTemp['ficerewfy'];
    						$vgen['ficerylfy'] = $CGTemp['ficerylfy'];
    					}
    					
    					$vgen['fallamount'] = ($vgen['fguanlu']+$vgen['ficerkzg']+$vgen['fpengzhangjie3']
    							+$vgen['fpengzhangjie']+$vgen['fbpvbeiya']+$vgen['fsovjiezhifa']
    							+$vgen['ffrvliuliang']+$vgen['fcbvfuiqi']+ $vgen['fyalicgq16']
    							+$vgen['fwenducgq16']+$vgen['fyalibiao12']+$vgen['fwenduji12']
    							+ ($vgen['ficerewfy'] + $vgen['ficerylfy'])*(1+$Cs['fsetffax']/100) );
    				}
    				
    			}
    			
    			
    			if($FRepKey == '14009' || $FRepKey == '14011' || $FRepKey == '14012' || $FRepKey == '14013' ){
	    			foreach ($insData as $kgen =>&$vgen)
	    			{
	    					if($vgen['jiazhangdata']){
	    						$vgen['jiazhangdatastr'] = join(",", array_column($vgen['jiazhangdata'], 'fid'));
	    						//gz_YjiazhangcbfMX
	    						$jzTEmp = [];
	    						foreach ($vgen['jiazhangdata'] as $kt =>$kv)
	    						{
	    							$jzTEmp[$kt]['fbrand'] = $kv['fbrand'] ;
	    							$jzTEmp[$kt]['fcode'] = $kv['fcode'] ;
	    							$jzTEmp[$kt]['fprodno'] = $vgen['fmodel'] ;
	    							$jzTEmp[$kt]['fallamount'] = $kv['ffaxamount'] ;
	    						}
// 	    						SqlServerUtil::sqlsrvAllTosql($this->SqlServer ,'gz_YjiazhangcbfMX' , $jzTEmp);
	    					//	SqlServerUtil::sqlsrvDelete($this->SqlServer ,'gz_Yjiazhangcbf' ,['fprodno'=>$vgen['fmodel']] );
	    					//	
	    					//	SqlServerUtil::sqlsrvAllTosql($this->SqlServer ,'gz_Yjiazhangcbf' , $jzTEmp);
	    					}
	    					unset($vgen['jiazhangdata']);
	    			}
    			}
//     			dd($insData);
    			SqlServerUtil::sqlsrvAllTosql($this->SqlServer ,$db , $insData);
    			//生产部列表 14010
    			if( in_array($FRepKey, ['14010' ]) ){
    				$cs = $this->getSystemProfile(['FSetSendSMS'   ]);
    				$this->genSendSms($cs['fsetsendsms'],getMkName($FRepKey).' ，机型为 ' .join("','", array_column($insData, 'fmodel')) .'已做新增');
    			}
    			
    			$this->writeLog(getMkName($FRepKey),'新增' , $FRepKey , $insData ,$opername );
    		}
//     		dd($resMX);
    		//明细
    		if(in_array($FRepKey,['14010',  '14007' ]) ){
    			SqlServerUtil::sqlsrvAllTosql($this->SqlServer ,$db.'MX' , $resMX);
    			//只针对 生产机型    -- 机加工 同步 
    			if(in_array($FRepKey,['14010'])){
    				$cs = $this->getSystemProfile(['FSetSendSMS' ,'FSetProdFY'  ]);
    				// 辅材成本 28006  -- 机加工  gz_Yfucaicbfjijia
    				$sqljj = " select  v1.*,u1.fdaojuxiaohao as dj  from gz_Yfucaicbfjijia v1
    				LEFT JOIN gz_YBaseProduce u1 on v1.fmodel = u1.fmodel
    				where v1.fmodel in ({$fmodelStr}) and u1.fdaojuxiaohao <> v1.fdaojufy " ;
    				$TempjjData = SqlServerUtil::execToSql($this->SqlServer,$sqljj );
    				//机加工
    				if(!empty($TempjjData)){
    					$JJData =[];
    					$TempjjDataT = arraykeyToLowerTo($TempjjData);
    					if($TempjjDataT){
    						foreach ($TempjjDataT as $k =>$v)
    						{
    							$JJData[$k]['fid'] = $v['fid'];
    							$JJData[$k]['fdaojufy'] = $v['dj'];
    							//合计    不需要分摊
    							$JJData[$k]['fallamount'] = ($JJData[$k]['fdaojufy']*$cs['fsetprodfy']??0) + ($v['ffentanfy']??0)  ;
    						}
    						$insjj = SqlServerUtil::sqlsrvkqUpdateTosql($this->SqlServer,'gz_Yfucaicbfjijia',$JJData,'fid');
    					}
    				}
    			}
    			
    			
    			//只针对技术中心    --焊接 同步 ，水电费 ，装试 
    			if(in_array($FRepKey,['14007'])){
    				$Cs = $this->getSystemProfile(['FSetShuiDianjgcjPrice' ,'FSetFuCaiDWPrice','FSetFFAX', 'FSetFuCai550Value' ,'FSetFuCai535Value','FSetFuCaiBZW535Value','FSetFuCaiBZW550Value' ]);
    				// 535
    				$fucaibzwvalue535 = empty($Cs['fsetfucaibzw535value'])?0:$Cs['fsetfucaibzw535value'] ;
    				$fucaivalue535 = empty($Cs['fsetfucai535value'])?0:$Cs['fsetfucai535value'] ;
    				// 550
    				$fucaibzwvalue550 = empty($Cs['fsetfucaibzw550value'])?0: $Cs['fsetfucaibzw550value'] ;
    				$fucaivalue550 = empty($Cs['fsetfucai550value'])?0: $Cs['fsetfucai550value'] ;
    				
    				// 水电费  26011    技术中心  ，，  自制件重量
    				$sqlsdf = "select  v1.*,u1.fzzjweight as zzj  from gz_Yshuidianf v1
    				LEFT JOIN gz_YBaseJS u1 on v1.fmodel = u1.fmodel where v1.fmodel in ({$fmodelStr})
    				and u1.fzzjweight <> v1.fjgcjDW " ;
    				$TempsdfData = SqlServerUtil::execToSql($this->SqlServer,$sqlsdf );
    				// 辅材成本 26008 结构
    				$sqlhj = "select  v1.*,u1.fzzjweight as zzj  from gz_Yfucaicbf v1
    				LEFT JOIN gz_YBaseJS u1 on v1.fmodel = u1.fmodel
    				where v1.fmodel in ({$fmodelStr})  and u1.fzzjweight <> v1.fzzjWeight " ;
    				$TemphjData = SqlServerUtil::execToSql($this->SqlServer,$sqlhj );
    				
    				// 辅材成本 28007 -- 装试  gz_Yfucaicbfzshi
    				$sqlzs = "select   u1.fpackage ,u1.ffuliao,u1.ffuliaopakeage,
    				v1.fdihao as dh,v1.fbaozhuangwu as bzw,
    				case when u1.ffuliaopakeage =535 then  {$fucaibzwvalue535}
    				when  u1.ffuliaopakeage =550 then  {$fucaibzwvalue550}
    				else 0 End as bzwxs,
    				case when u1.ffuliaopakeage =535 then {$fucaivalue535}
    				when  u1.ffuliaopakeage =550 then  {$fucaivalue550}
    				else 0 End as dhxs,
    				v1.*
    				from gz_Yfucaicbfzshi v1
    				LEFT JOIN gz_YBaseJS u1 on v1.fmodel = u1.fmodel
    				where v1.fmodel in ({$fmodelStr})
    				and ( u1.fpackage <> (case when u1.ffuliaopakeage =535 then v1.fbaozhuangwu/{$fucaibzwvalue535}
    				when  u1.ffuliaopakeage =550 then v1.fbaozhuangwu/{$fucaibzwvalue550}
    				else 0 End)  or u1.ffuliao <> (case when u1.ffuliaopakeage =535 then v1.fdihao/{$fucaivalue535}
    				when  u1.ffuliaopakeage =550 then v1.fdihao/{$fucaivalue550}
    				else 0 End) ) " ;
    				$TempzsData = SqlServerUtil::execToSql($this->SqlServer,$sqlzs );
    				//只对 水电费  26011 ，辅材 做更新操作
    				if(!empty($TempsdfData)){
    					// $TempDataJS -- 技术 自制件重量
    					$SDFData =[];
    					$TempsdfDataT = arraykeyToLowerTo($TempsdfData);
    					if($TempsdfDataT){
    						foreach ($TempsdfDataT as $k =>$v)
    						{
    							$SDFData[$k]['fid'] = $v['fid'];
    							$SDFData[$k]['fjgcjdwprice'] = empty($Cs['fsetshuidianjgcjprice'])?0:$Cs['fsetshuidianjgcjprice'] ;//参数设置水电费价格
    							$SDFData[$k]['fjgcjdw'] = $v['zzj'];
    							$SDFData[$k]['fjgcjdwamount'] = $SDFData[$k]['fjgcjdw'] * $SDFData[$k]['fjgcjdwprice']  ;
    							//水电费合计
    							$SDFData[$k]['fallamount'] = $SDFData[$k]['fjgcjdwamount']+ ($v['fjijiacj']??0 ) + ($v['fzhuangshicj']??0 )  + ($v['fhanjiecj']??0 ) ;
    							//水电费合计 含税
    							$SDFData[$k]['ffaxallamount']  = (floatval($SDFData[$k]['fjgcjdwamount'])  + floatval($v['fjijiacj'])
    									+ floatval($v['fzhuangshicj']) + ($v['fhanjiecj']??0 ))*(1+$Cs['fsetffax']/100)   ;
    						}
    						$inssdf = SqlServerUtil::sqlsrvkqUpdateTosql($this->SqlServer,'gz_Yshuidianf',$SDFData,'fid');
    					}
    					
    				}
    				//焊接  -- 技术 自制件重量
    				if(!empty($TemphjData)){
    					// // 结构车间-制造费用表  用技术中心的自制件重量引过来
    					// 按吨位计算的成本 fdunweicb  = 根据单价 乘以 吨位    这里 还差一个 吨位计算成本
    					$HJData =[];
    					$TemphjDataT = arraykeyToLowerTo($TemphjData);
    					if($TemphjDataT){
    						foreach ($TemphjDataT as $k =>$v)
    						{
    							$HJData[$k]['fid'] = $v['fid'];
    							$HJData[$k]['fdunweiprice'] = empty($Cs['fsetfucaidwprice'])?0:$Cs['fsetfucaidwprice'];//辅材成本 -- 单位吨位价格
    							$HJData[$k]['fzzjweight'] = $v['zzj'];
    							$HJData[$k]['fdunweicb']  =  ($HJData[$k]['fzzjweight']??0) *  $HJData[$k]['fdunweiprice'] ;
    							$HJData[$k]['fallamount'] =  ($v['fzjyouqi']??0) + ($v['ftuihuocb']??0 ) + ($v['fqitaftcb']??0 ) + $HJData[$k]['fdunweicb']??0  ;
    						}
    						$inshj = SqlServerUtil::sqlsrvkqUpdateTosql($this->SqlServer,'gz_Yfucaicbf',$HJData,'fid');
    					}
    				}
    				//装试 -- 技术低耗  ，包装物
    				if(!empty($TempzsData)){
    					$ZSData =[];
    					$TempzsDataT = arraykeyToLowerTo($TempzsData);
    					if($TempzsDataT){
    						foreach ($TempzsDataT as $k =>$v)
    						{
    							$ZSData[$k]['fid'] = $v['fid'];
    							// $Cs
    							$ZSData[$k]['fdihao'] = $v['dhxs']* $v['ffuliao']  ;
    							$ZSData[$k]['fbaozhuangwu'] = $v['bzwxs']* $v['fpackage']  ;
    							$ZSData[$k]['fallamount'] =  ($ZSData[$k]['fdihao']??0) + ($ZSData[$k]['fbaozhuangwu']??0 ) + ($v['fyoulvqi']??0 ) + ($v['fqitayoupin']??0)  + ($v['ffentanfycj']??0 ) + ($v['ffentanfysczl']??0)  ;
    						}
    						$inszs = SqlServerUtil::sqlsrvkqUpdateTosql($this->SqlServer,'gz_Yfucaicbfzshi',$ZSData,'fid');
    					}
    				}
    				
    			}
    			
    			
    		}
    		
    	}
    	
    	//修改
    	if(in_array($FRepKey, [ '26024',   '27001','27002','27003','27004','27005','27006','27007','27008','27009'  ,'27010' ,'27011',] )) {
    		    	$fidField ='fid';
    		    	// 修改 --  updateRecords,
    		    	$updateRecords = isset( $data['updateRecords'])?$data['updateRecords'] :[];
    		    	if(!empty($updateRecords)){
    		    		$Cshu = $this->getSystemProfile([ 'FSetFFAX',    ]);
    		    		foreach ($updateRecords as $kup=>&$vup)
    			    		{
    			    			$insData =[];
    			    			$where= [];
    		
    			    			$where[$fidField] = $vup[$fidField];
    		
    			    			foreach ($getVexTableColumnData as  $up)
    				    			{
    				    				if( ( empty($vup[$up['frepfld']]) || $vup[$up['frepfld']] =='.00' ) && $up['freptype'] == 131 ){
    				    					$vup[$up['frepfld']] =0;
    				    				}
    			
    				    				if( empty($vup[$up['frepfld']])  && ($up['freptype'] == 202 || $up['freptype'] == 200 ) ){
    				    					$vup[$up['frepfld']] = '';
    				    				}
    			
    				    				$insData[$up['frepfld']] = $vup[$up['frepfld']] ;
    				    				
    				    				//船检固定参数更新
    				    				if($FRepKey == 26024){
    				    					// fhuilv -- 汇率
    				    					//证书费(人民币)
    				    					$insData['fzhengshufrmb']= $vup['fzhengshuf']* $vup['fhuilv'] ;
    				    					//过程检验(人民币)
    				    					$insData['fscjjrmb']= $vup['fscjj']* $vup['fhuilv'] ;
    				    					$insData['fqueding']= $insData['fzhengshufrmb']+  $insData['fscjjrmb']+ $vup['flutufrmb'] ;
    				    					$insData['fnoxpfmxrmb']= $vup['fnoxpfmx']* $vup['fhuilv'] ;
    				    					$insData['fnoxpfzxrmb']= $vup['fnoxpfzx']* $vup['fhuilv'] ;
    				    				}
    				    			}
    				    			if($FRepKey == 27010){
    				    				$insData['fcreatetime']= getCurrentTime();
    				    				$insData['fguanlu'] = 0;
    				    				$insData['ficerkzg'] = 0;
    				    				$insData['fpengzhangjie3'] = 0;
    				    				$insData['fpengzhangjie'] = 0;
    				    				$insData['fbpvbeiya'] = 0;
    				    				$insData['fsovjiezhifa'] = 0;
    				    				$insData['ffrvliuliang'] = 0;
    				    				$insData['fcbvfuiqi'] = 0;
    				    				$insData['fsovjiezhifa'] = 0;
    				    				
    				    				$insData['ffrvliuliang'] = 0;
    				    				$insData['fcbvfuiqi'] = 0;
    				    				$insData['fyalicgq16'] = 0;
    				    				$insData['fwenducgq16'] = 0;
    				    				$insData['fyalibiao12'] = 0;
    				    				$insData['fwenduji12'] = 0 ;
    				    				$a1 = " select fguanlu,ficerkzg,fpengzhangjie3,fpengzhangjie,fbpvbeiya,fsovjiezhifa,
										ffrvliuliang,fcbvfuiqi,fsovjiezhifa,ffrvliuliang,fcbvfuiqi,fyalicgq16,
										fwenducgq16,fyalibiao12,fwenduji12 from {$db} where fegcmodel = {$vup['fegcmodel']} ";
    				    				$JSTemp = SqlServerUtil::execTosql($this->SqlServer, $a1 ,2);
    				    				if($JSTemp){
    				    					$insData['fguanlu'] = $JSTemp['fguanlu'];
    				    					$insData['ficerkzg'] = $JSTemp['ficerkzg'];
    				    					$insData['fpengzhangjie3'] = $JSTemp['fpengzhangjie3'];
    				    					$insData['fpengzhangjie'] = $JSTemp['fpengzhangjie'];
    				    					$insData['fbpvbeiya'] = $JSTemp['fbpvbeiya'];
    				    					$insData['fsovjiezhifa'] = $JSTemp['fsovjiezhifa'];
    				    					$insData['ffrvliuliang'] = $JSTemp['ffrvliuliang'];
    				    					$insData['fcbvfuiqi'] = $JSTemp['fcbvfuiqi'];
    				    					$insData['fsovjiezhifa'] = $JSTemp['fsovjiezhifa'];
    				    					
    				    					$insData['ffrvliuliang'] = $JSTemp['ffrvliuliang'];
    				    					$insData['fcbvfuiqi'] = $JSTemp['fcbvfuiqi'];
    				    					$insData['fyalicgq16'] = $JSTemp['fyalicgq16'];
    				    					$insData['fwenducgq16'] = $JSTemp['fwenducgq16'];
    				    					$insData['fyalibiao12'] = $JSTemp['fyalibiao12'];
    				    					$insData['fwenduji12'] = $JSTemp['fwenduji12'];
    				    				}
    				    				$insData['fallamount'] = ($insData['fguanlu']+$insData['ficerkzg']+$insData['fpengzhangjie3']
    				    						+$insData['fpengzhangjie']+$insData['fbpvbeiya']+$insData['fsovjiezhifa']
    				    						+$insData['ffrvliuliang']+$insData['fcbvfuiqi']+ $insData['fyalicgq16']
    				    						+$insData['fwenducgq16']+$insData['fyalibiao12']+$insData['fwenduji12']
    				    						+($insData['ficerewfy'] + $insData['ficerylfy']) *(1+$Cshu['fsetffax']/100));
    				    				
    				    			}
    				    			if($FRepKey == 27011){
    				    				$insData['fcreatetimecg']= getCurrentTime();
    				    				$insData['ficerewfy'] = 0;
    				    				$insData['ficerylfy'] = 0;
    				    				$a1 = " select ficerewfy,ficerylfy  from {$db} where fegcmodel = {$vup['fegcmodel']} ";
    				    				$CGTemp = SqlServerUtil::execTosql($this->SqlServer, $a1 ,2);
    				    				if($CGTemp){
    				    					$insData['ficerewfy'] = $CGTemp['ficerewfy'];
    				    					$insData['ficerylfy'] = $CGTemp['ficerylfy'];
    				    				}
    				    				
    				    				$insData['fallamount'] = ($insData['fguanlu']+$insData['ficerkzg']+$insData['fpengzhangjie3']
    				    						+$insData['fpengzhangjie']+$insData['fbpvbeiya']+$insData['fsovjiezhifa']
    				    						+$insData['ffrvliuliang']+$insData['fcbvfuiqi']+ $insData['fyalicgq16']
    				    						+$insData['fwenducgq16']+$insData['fyalibiao12']+$insData['fwenduji12']
    				    						+($insData['ficerewfy'] + $insData['ficerylfy']) *(1+$Cshu['fsetffax']/100) );
    				    			}
//     				    			dd($insData , $a1);
    			    			SqlServerUtil::exeupdateTosql($this->SqlServer,$db,$insData,$where);
    			    			$this->writeLog(getMkName($FRepKey),'修改' , $FRepKey , $insData ,$opername );
    			    		}
    		
    		    	}
    	}

    	
    	// 删除 --  removeRecords
    	if(in_array($FRepKey, [ '26024',] )) {
    		$removeRecords = isset( $data['removeRecords'])?$data['removeRecords'] :[];
    		if(!empty($removeRecords)){
    		    $Fids =[];
    		    $Fids = join("','", array_column($removeRecords, 'fid'));
    		    // 			dd($Fids);
    		    SqlServerUtil::sqlsrvDelete($this->SqlServer,$db, ['fid'=>"'".$Fids ."'" ],true);
    		    $this->writeLog(getMkName($FRepKey),'删除' , $FRepKey , $removeRecords ,$opername );
    		 }
    		
    	}
 
    	showMsg(0,'成功' );
    }
    
    
    /**
    * 编辑 
    * @date: 2023年1月4日 下午4:48:42
    * @author: juyi
    */
    public function billGenEdit(Request $request){
    	$finterid =$request->fid ;
    	$FRepKey = $request->FRepKey; // 26005--清单
    	$opername  = $request->opername?$request->opername:'' ;
    	
    	$finteridStr = " and v1.fid = {$finterid}" ;
    	$sqlData = getfileSql($FRepKey ,1);
    	if(!$sqlData){
    		showMsg(1,'设置Sql不存在');
    	}
    	$sql= $sqlData ;
    	$vowels = array("\n", "\r", "\t");
    	$sql = str_replace($vowels, ' ',$sql);
    	
    	$sql = str_replace('{$fidStr}', $finteridStr, $sql);
//     	    	dd($sql);
    	$result =[];
    	$res = SqlServerUtil::execTosqlOK($this->SqlServer,$sql);
    	if($res){
    		$result = arraykeyToLower($res);
    		foreach ($result as $k => &$v)
    		{ 
    			if(in_array($FRepKey ,['14009' , '14011' ,'14012','14013' ])){
    				$v['jiazhangdata'] = $this->getJzBJData($v['fmodel'],$v['fbillno'] ,$FRepKey);
    			}
    			if(in_array($FRepKey ,[ '34001'])){
    				$v['jiazhangdata'] = $this->getJzBJData($v['fmodel'],$v['fbillnoentry'],$FRepKey );
    			}
    			
    			foreach ($v as $k1=>$v1)
    			{
    				
    				if( $v[$k1] ==='.00' || ($v[$k1]>0 && $v[$k1]<1) ){
    					if(stripos( $v[$k1] , '%' ) === false){
    						$v[$k1] = floatval($v1);
    					}
    					
    				}
    			}
    		}
    	}
    	showMsg(0,'成功',$result);
    }
    
    /**
    * 删除
    * @date: 2023年1月4日 下午4:48:54
    * @author: juyi
    */
    public function billGenDel(Request $request){
    	$finterid =$request->fid ;
    	$FRepKey = $request->FRepKey; // 26005--清单
    	$opername  = $request->opername?$request->opername:'' ;
    	
    	$db = columnBiao($FRepKey);//表名
    	$finteridStr = " and v1.fid = {$finterid}" ;
    	
    	$opername  = $request ->get('opername')?$request ->get('opername') :'';
    	$data  = $request ->get('data');
    	$qkid = sqlsrv_query($this->SqlServer,"DELETE {$db} WHERE Fid in ({$finterid}) ");
    	 
    	if($qkid){
    		$this->writeLog(getMkName($FRepKey),'删除' , $FRepKey , $data ,$opername);
    		showMsg(200,'删除成功');
    	}else{
    		showMsg(400,'删除失败');
    	}
    	
    }
    
    /**
    * 单据list  
    * @date: 2023年1月5日 下午5:37:14
    * @author: juyi
    */
    public function billGenList(Request $request){
    	 
    	$FRepKey = $request->FRepKey; // 26005--清单
    	$opername  = $request->opername?$request->opername:'' ;
    	 
    	$sqlData = getfileSql($FRepKey ,1);
    	if(!$sqlData){
    		showMsg(1,'设置Sql不存在');
    	}
    	$sql= $sqlData ;
    	$vowels = array("\n", "\r", "\t");
    	$sql = str_replace($vowels, ' ',$sql);
    	
    	// dd($sql);
    	$result =[];
    	$res = SqlServerUtil::execTosqlOK($this->SqlServer,$sql);
    	if($res){
    		$result = arraykeyToLower($res);
    		foreach ($result as $k => &$v)
    		{
    			foreach ($v as $k1=>$v1)
    			{
    				if( $v[$k1] ==='.00'  || ($v[$k1]>0 && $v[$k1]<1)){
    					$v[$k1] = floatval($v1);
    				}
    			}
    		}
    	}
    	showMsg(0,'成功',$result);
    }
	    
    /**
    * 预算成本生成  == 正式报价
    * 预算成本生成 
    * @date: 2022年12月19日 下午4:45:53
    * @author: juyi
    */
    public function yuSuanCB(Request $request){
    	$keywordStr="";
    	if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
    		$keyword =  $request->keyword ;
    		$keywordTmp = explode(',',$keyword);
    		if(count($keywordTmp)>1){
    			$tmp30002 = '';
    			foreach ($keywordTmp as $v)
    			{
    				$tmp30002 .= " or charindex('{$v}',v1.Fmodel)>0 or charindex('{$v}',v1.Fbillno)>0 " ;
    			}
    			$keywordStr=' and ( '.trim($tmp30002,' or') .")";
    		}else{
    			$keywordStr=" and ( charindex('{$keyword}',v1.Fmodel)>0 or charindex('{$keyword}',v1.Fbillno)>0   )";
    		}
    	}
    	$fbrandStr="";
    	if ($request->has('fbrand') and $request->fbrand != '' and !empty($request->fbrand)) {
    		$fbrand =  $request->fbrand ;
    		$fbrandStr=" and u1.fbrand = '{$fbrand}'  ";
    	}
    	//参数值
    	$CsData =  $this->getSystemProfile();
    	//税率
    	$fax = $CsData['fsetffax']/100; 
    	//汇率
    	$huilv = $CsData['fsethuilv']; 
    	//-气缸单价
    	$qigang = $CsData['fsetqigangprice']; 
    	//燃气单价
    	$ranqi = $CsData['fsetranqiprice']; 
    	//柴油单价
    	$chaiyou = $CsData['fsetchaiyouprice']; 
    	//直接人工
    	$fhanjiePrice= $CsData['fsetrgjiegoucjprice'];
    	$fjijiaPrice = $CsData['fsetrgjijiacjprice'];
    	$fzhuangshiPrice = $CsData['fsetrgzhuangshicjprice']; 
    	$fsetzhaunlifeibl = $CsData['fsetzhaunlifeibl']; 
    	$FSetCZBQPrice  = $CsData['fsetczbqprice']; 
    	//专利费
    	$ZlData = SqlServerUtil::execToSql($this->SqlServer, "select * from gz_Yzhuanlif " );
    	//排放检测费
    	$pfjjData = SqlServerUtil::execToSql($this->SqlServer, "select *  from gz_Ypfceshif " );
     
    	//FSetSFCWGLFY
    	//预算成本生成 
    	//税率
    	$ww_113 = 1+$fax ;
    	//委外
    	$ww_103 = $CsData['fsetweiwaif'] ;    	$ww_10000 = $CsData['fsetprodfy'] ;
    	$ww_10 = $CsData['fsetprodgzftts'] ;   	$ww_5 = $CsData['fsetprodxhdjftts'] ;
    	//图纸送审
    	$ww_106 = $CsData['fsettuzhiss'] ;
    	//运保费
    	$ww_109 = $CsData['fsetyunbaof'] ;
    	//财务费用
    	$ww_005 = $CsData['fsetsfcwglfy'] ;
    	//管理费用
    	$ww_005gl = $CsData['fsetglfy'] ;
    	//船检费CCS
    	$cjf_106 = $CsData['fsetchuanjianccs'] ;
    	//海外测试调试费
    	$hwtsf = empty($CsData['fsethaiwaitsf'])? 0: $CsData['fsethaiwaitsf'] ;
    	//改造费
    	$gzf = empty($CsData['fsetgaizaof'])? 0: $CsData['fsetgaizaof'] ;
    	//设置置甲醇机管理费用 (正式报价)
    	$jcj_005gl = $CsData['fsetjcjglfy'] ;
    	//设置甲醇机税费及财务费用比例
    	$jcj_005 = $CsData['fsetjcjsfcwglfy'] ;
    	//增加甲醇机的利润率
    	$jcj_005lv = $CsData['fsetjcjlv'] ;
    	
    	//船级社设置 FSetChuanjisheBase
    	$cjsBase  = explode( ',' , $CsData['fsetchuanjishebase'] );
    	// 图纸送审 
    	$ftuzhissStr = ' 0 as ftuzhiss, ';
    	if($cjsBase){
    		$ftuzhissStr = '';
    		$ftuzhissStr .=' case ' ;
    		foreach ($cjsBase as $cjs)
    		{
    			if( $cjs == 'DNV'){
    				$ftuzhissStr .= " when v1.fchuanjishe = '{$cjs}'  then Round(isnull(u1.ftuzhissDNVGL,0)*{$ww_113}/v1.fqty ,2) " ;
    			}else{
    				$ftuzhissStr .= " when v1.fchuanjishe = '{$cjs}'  then Round(isnull(u1.ftuzhiss{$cjs},0)*{$ww_113}/v1.fqty ,2) " ;
    			}
    		}
    		$ftuzhissStr .=' else 0 END as ftuzhiss, ';
    	}
    	
    	//船检费 
    	$cjfStr = ' 0 as fchuanjianf , ';
    	if($cjsBase){
    		$cjfStr = '';
    		$cjfStr .=' case ' ;
    		foreach ($cjsBase as $cjs)
    		{
    			if( in_array( $cjs , ['CCS','ABS','LR','BV','DNV','NK' ] )){
    				if( $cjs == 'DNV'){
    					$cjfStr .= " WHEN cjfDNV.fchuanjishe = v1.fchuanjishe and cjfDNV.fchuanjishe = '{$cjs}' THEN  Round(cjfDNV.fchanjianfeiDNV *{$ww_113},2) " ;
    				}elseif($cjs == 'CCS'){
    					$cjfStr .= " WHEN cjf.ftype = v1.fchuanjishe and cjf.ftype ='{$cjs}' THEN  Round(cjf.fallamount/{$cjf_106} *{$ww_113},2)" ;
    				}else{
    					$cjfStr .= " WHEN cjf.ftype = v1.fchuanjishe and cjf.ftype ='{$cjs}'  THEN  Round(cjf.fallamount *{$ww_113},2) ";
    				}
    				
    			}else{
    				$cjfStr .= " WHEN cjfqt.ftype = v1.fchuanjishe and cjfqt.ftype ='{$cjs}'  THEN  Round(cjfqt.fallamount *{$ww_113},2) ";
    			}
    		}
    		$cjfStr .=' else 0 END as fchuanjianf, ';
    	}
    	
    	//正式报价
    	$sql ="  select v1.fbillno,v1.fmodel ,v1.fsjpower,v1.fhtpower,v1.fcxpower, v1.fqty,v1.fzlyhAmount, v1.fmarketprice,0 as fisqr,
    	v1.fzengsong,0 as fyongjin ,v1.fisyongjinbl,v1.fchuanjishe,v1.fisjingneijingwai,v1.fyongjinbl,v1.fyongjinjine,
		v1.fyjdate,  zl.fsetzhaunlifeibl,zl.ffax as ffaxzl ,zl.fPatentfee as fzlsfbiaozhun,zl.FExchangeRate as fzlhuilv,
		v1.fzhibaoqi,  v1.fisEGR,v1.fisSCR,v1.fisryrq,v1.fcustomer,v1.fcustomerName,v1.fmodelNO,v1.fjsxyNO,
		CASE  WHEN v1.fishwtsf = '是' THEN {$hwtsf}  else 0 End as fhaiwaitsf, v1.fishwtsf,
		 
		u1.ffuliaopakeage,	u1.fbrand,u1.funit  ,  u1.fzjWeight  as ftonnage ,
		(u1.fhanjiegs + u1.fjijiags + u1.fzhuangshigs )  as fworkhour , u1.fSCRgs as fworkhourScr , u1.fEGRgs as  fworkhourEgr ,
		Round(isnull( cgcb.fallAmount, 0 )* {$ww_113},2)  as  ftaxSinglezjcl,
		Round(isnull( cgcb.fallAmount, 0 ) ,2)  as  fnotaxsinglezjcl,
		0 as fPatentfee, 
		isnull(jzcb.fallAmount,0) as fjiazhangcb ,
		isnull(jzcbjs.fallAmount,0) as fjiazhangcbJS ,
		isnull(jzcbcg.fallAmount,0) as fjiazhangcbCG ,
		isnull(jzcbqt.fallAmount,0) as fjiazhangcbQT ,
		
		{$cjfStr}
 		
 		Round((yq.fnoranyou*yq.fprice + yq.fnoranqi *yq.fgasPrice+ yq.fnoqigang*yq.fCylinderoilPrice),2)  as fNooneyouqifee, 
		Round(isnull(yq.fAllamount,0)*{$ww_113},2) as fyouqifee,
		Round(isnull(pfcs.fallAmount,0)* {$ww_113}/v1.fqty ,2) as  femissionfee,
		Round(isnull(tz.fallAmount,0)* {$ww_113}/5,2)  as fDrawingfee,

		Round(isnull(zlcb.fallAmount,0) ,2) as fqualityCost,
		Round((isnull(prod.fweiwaiAmount,0)*{$ww_10000}/{$ww_103})* $ww_113 ,2) as fweiwaifee,

		round(((prod.fhanjiegz +prod.fjijiagz +prod.fzhuangshigz +prod.fshichegz)/{$ww_10} +prod.ffayungzzj)*{$ww_10000},2)  as fworkwhole,
		round(((prod.fhanjiegz +prod.fjijiagz +prod.fzhuangshigz +prod.fshichegz)/{$ww_10} +prod.ffayungzfd)*{$ww_10000},2)  as fworkparted,
		Round(isnull(prod.fxjxtsdaoju,0)*{$ww_10000}/{$ww_5} ,2)  as fcutter ,
		
		Round(isnull(fjhj.fallamount ,0)*{$ww_113},2) as fweldWorkfc ,
    	Round(isnull(fjjj.fallamount ,0) ,2) as fmachineWorkfc,
    	Round(isnull(fjzs.fallamount ,0)*{$ww_113},2) as  ftestWorkfc,
		0 as ffucaitotal,

		Round(isnull(sd.fjgcjDWAmount,0) + isnull(sd.fhanjiecj,0) ,2) as  fweldWorksd ,
    	Round(isnull(sd.fjijiacj,0),2)  as  fmachineWorksd ,
    	Round(isnull(sd.fzhuangshicj,0),2)  as ftestWorksd ,
    	0  as fsdTotal,

    	{$ftuzhissStr} 
		
		isnull( CONVERT(DECIMAL(28,2), u1.fniuzhenRMB), 0 ) AS fniuzhenjisuanfee,
		Round((isnull(convert(DECIMAL(28,2) ,v1.fyunbaof),0) /{$ww_109}*{$ww_113}),2) AS fyunfei,

		isnull(shts.fallAmount,0) as fsaleCost ,
		Round(u1.fhanjiegs * u1.fhanjiePrice*{$ww_113},2)  as fweldRg ,
		Round(u1.fjijiags * u1.fjijiaPrice*{$ww_113},2)  as fjjgRg ,
		Round(u1.fzhuangshigs * u1.fzhuangshiPrice*{$ww_113},2) as fzhuangshiRg ,
		0 as fzhijieRg ,

		Round(isnull(zj.fcjZjAmount,0)*{$ww_113},2) as fzhejiu ,
		isnull(icer.fallamount,0)  as fguanlucbAmount,
		isnull(yq.fAllamount,0)  as fyouqifeeTemp,
		isnull(scr.fICERRYAmount,0) as fICERRYAmount,
		isnull(scr.fICERRQAmount,0) as fICERRQAmount,
		isnull(scr.fEcoEGRAmount,0) as fEcoEGRAmount,
		
		isnull(scr.fSCRAmount,0) as fSCRAmount,
		isnull(scr.fEGRAmount,0) as fEGRAmount,
		isnull(jiachun.fallamount,0) as fjiachunAmount,
		0 as fICERAmount,

		0 as fSCRCost , 
		0  as fEGRCost ,
		0 as fscrIncWork ,
		0 as fscrpfcsZS,
		0 as fegrpfcsZS,
		{$gzf} as fgaizaof

		from 
		gz_YBaseSC v1 
		left join gz_YBaseJS_BAOJIA u1 on v1.fmodel = u1.fmodel  and u1.fjybjbillno = v1.fbillno
		LEFT JOIN (SELECT SUM(fallAmount ) fallAmount,fjybjbillno FROM gz_Ycaigoucbf_BAOJIA GROUP BY fjybjbillno) cgcb on cgcb.fjybjbillno = v1.fbillno
		left join gz_YBaseProduce_BAOJIA prod on prod.fjybjbillno = v1.fbillno
	    LEFT JOIN (SELECT SUM(fallAmount ) fallAmount,fjybjbillno FROM gz_Yjiazhangcbf_BAOJIA GROUP BY fjybjbillno) jzcb on jzcb.fjybjbillno = v1.fbillno
		LEFT JOIN ( SELECT SUM ( fallAmount ) fallAmount, fjybjbillno FROM gz_Yjiazhangcbf_BAOJIA WHERE Fbm = 'JS' GROUP BY fjybjbillno ) jzcbjs ON jzcbjs.fjybjbillno = v1.fbillno
		LEFT JOIN ( SELECT SUM ( fallAmount ) fallAmount, fjybjbillno FROM gz_Yjiazhangcbf_BAOJIA WHERE Fbm = 'CG' GROUP BY fjybjbillno ) jzcbcg ON jzcbcg.fjybjbillno = v1.fbillno
		LEFT JOIN ( SELECT SUM ( fallAmount ) fallAmount, fjybjbillno FROM gz_Yjiazhangcbf_BAOJIA WHERE Fbm = 'QT' GROUP BY fjybjbillno ) jzcbqt ON jzcbqt.fjybjbillno = v1.fbillno

  		left join gz_Yzhiliangcb_BAOJIA zlcb on zlcb.fjybjbillno = v1.fbillno
		left join gz_Yfucaicbf_BAOJIA  fjhj on fjhj.fjybjbillno = v1.fbillno
    	left join gz_Yfucaicbfjijia_BAOJIA  fjjj on fjjj.fjybjbillno = v1.fbillno
    	left join gz_Yfucaicbfzshi_BAOJIA fjzs on fjzs.fjybjbillno = v1.fbillno
		
		left join gz_Yshuidianf_BAOJIA sd on sd.fjybjbillno = v1.fbillno
    	left join gz_Yshtswhcb_BAOJIA shts on shts.fjybjbillno = v1.fbillno
    	left join gz_Yzhejiuf_BAOJIA zj on zj.fjybjbillno = v1.fbillno
		
		left join gz_Yyouqif_BAOJIA yq on yq.fjybjbillno = v1.fbillno
		left join gz_Yzhuanlif_BAOJIA zl on zl.fjybjbillno = v1.fbillno
		left join gz_Ypfceshif_BAOJIA pfcs on pfcs.fjybjbillno = v1.fbillno
		left join gz_Ytuzhif_BAOJIA tz on tz.fjybjbillno = v1.fbillno
		left join gz_Ychuanjianfgd cjf on cjf.fjybjbillno = v1.fbillno
		left join gz_YchuanjianfDNV_BAOJIA cjfDNV on cjfDNV.fjybjbillno = v1.fbillno
		left join gz_YchuanjianfQT cjfqt on cjfqt.fjybjbillno = v1.fbillno

		left join gz_YjzSCREGRHZ scr on scr.fbillno = v1.fbillno
		left join gz_YjzJiaChunQT  jiachun on jiachun.fbillno = v1.fbillno
		left join gz_YjzICERDB_BAOJIA  icer on icer.fjybjbillno = v1.fbillno
		
		where 1=1 and v1.fisqr = 3   {$keywordStr} {$fbrandStr}  
    	and v1.fbillno not in ( select fbillno from gz_YbaojiadanCB where  FStatus =1)  order by v1.fbillno desc ";
    	// 正式报价
//     	echo $sql;die;
    	$res = SqlServerUtil::execToSql($this->SqlServer, $sql );
    	$result =[];
//     	dd($res);

    	if($res ){
    		$result = arraykeyToLower($res);
    		foreach ($result as $k =>&$v)
    		{
    			$fzhuanliTemp = 0 ;
    			$fhuilvTemp = 0 ;
    			$fjiachunamountTmp  = 0;
     			//专利费  --预算成本 
    			$v['fpatentfee'] = round(getZLBaojia($v['fbrand'],$v['fyjdate'] ,$v['fsetzhaunlifeibl'], $v['fzlsfbiaozhun'],$v['fsjpower'],$v['fzlyhamount'],$v['fzlhuilv'])*$ww_113 ,2);
    			//辅材合计
    			$v['ffucaitotal'] = $v['fweldworkfc'] + $v['fmachineworkfc'] + $v['ftestworkfc'] ;
    			//水电合计
    			$v['fsdtotal'] = $v['fweldworksd'] + $v['fmachineworksd'] + $v['ftestworksd'] ;
    			//直接人工成本
    			$v['fzhijierg'] = $v['fweldrg'] + $v['fjjgrg'] + $v['fzhuangshirg'] ;
    			//佣金
    			$v['fyongjin'] = getYongjin($v['fmarketprice'] ,$v['fisyongjinbl'], $v['fisjingneijingwai'],$v['fyongjinbl'],$v['fyongjinjine'] ) ;
    			//超期质保费
    			$v['fcbzsfzhibaof'] =round( getYueFenValue($v['fzhibaoqi'])* $FSetCZBQPrice /6 ,2)  ;
    			//fICERAmount  == ICER
    			$v['ficeramount'] = getIcerData($v['ficerryamount'] ,$v['ficerrqamount'] , $v['fyouqifeetemp'] ,$v['fisryrq'] ,$ww_113)  ;
    			//fSCRAmount  == SCR
    			$v['fscramount'] = getScrData( $v['fscramount'], $v['fyouqifeetemp'] ,$v['fisscr'] ,$ww_113 )  ;
    			//fEGRAmount  == EGR
      			$v['fegramount'] = getEgrData( $v['fegramount'], $v['fyouqifeetemp'] ,$v['fecoegramount'], $v['fisegr'] ,$ww_113 )  ;
    			 //甲醇机
      			$fjiachunamountTmp  = getJIAChunJIData($v['fjiachunamount'] , $v['fyouqifeetemp']    ,$ww_113 ) ;
      			$v['fjiachunamount']  = ($fjiachunamountTmp - $v['fegramount'] ) <0 ? 0:$fjiachunamountTmp - $v['fegramount'] ;
    			//fEcoEGRAmount
//     			$v['fecoegramount'] = getEcoEGRData($v['fecoegramount'] , $v['fyouqifeetemp']    ,$ww_113 ) ;
    			
    			//固定部分小计   fworkparted 工装分装
    			$v['fgdbfxiaoji'] = round($v['ftaxsinglezjcl'] +$v['fyouqifee']+$v['ffucaitotal']+$v['fsdtotal']+$v['fsalecost']
    					+$v['fqualitycost']+$v['fweiwaifee']+$v['fdrawingfee']+$v['fworkwhole']+$v['fcutter']+$v['fzhijierg'] ,2)  ;
//     			dd($v['fgdbfxiaoji']);
    			//变动部分小计
    			$v['fbdbfxiaoji'] = round($v['fpatentfee'] +$v['fchuanjianf']+$v['fyunfei']+$v['femissionfee']+$v['ftuzhiss']  ,2) ;
    			//项目专项成本小计	fxmzxCB
    			$v['fxmzxcb'] = round($v['fjiazhangcbcg'] +$v['fjiazhangcbjs']+$v['fjiazhangcbqt'] +$v['fscramount']+$v['fegramount'] 
    			+$v['ficeramount']+$v['fjiachunamount']+$v['fguanlucbamount'] +$v['fhaiwaitsf']+$v['fyongjin'] +$v['fcbzsfzhibaof']
    					+$v['fscrpfcszs'] +$v['fegrpfcszs']+$v['fgaizaof']+$v['fzengsong'] ,2)  ;
    			
    			//小计  =  项目专项成本小计 + 变动部分小计  + 固定部分小计 
    			$v['fxiaoji'] = round($v['fxmzxcb'] + $v['fbdbfxiaoji'] + $v['fgdbfxiaoji'],2) ;
    			 
    			//判断是否是甲醇机
    			if( stripos( strtoupper($v['fmodel']) , 'LGIM' ) !== false)    {
    				// 税费及财务费用 = (小计+ 折旧费用 ) *设置置甲醇机管理费用 (正式报价) 0.05
    				$v['fcwfy'] = round(( $v['fxiaoji'] +$v['fzhejiu']) * $jcj_005 ,2); 
    				// 管理费用 
    				$v['fglfy'] =  round(($v['fxiaoji'] +$v['fzhejiu'] + $v['fcwfy'] )* $jcj_005gl ,2) ; 
    				// 变动成本小计 =  小计 + 税费及财务费用   + 管理费用 
    				$v['fbdcb'] = $v['fxiaoji'] + $v['fzhejiu'] + $v['fcwfy'] + $v['fglfy'] ;
    				// 总成本费用
    				$v['fzcbfy'] =   round( $v['fbdcb'] * $jcj_005lv ,2) ;
    				
    			}else{
	    			// 税费及财务费用 = 小计 *0.05
	    			$v['fcwfy'] = round($v['fxiaoji']  * $ww_005 ,2); 
	    			// 管理费用  
	    			$v['fglfy'] =  round(($v['fxiaoji'] + $v['fcwfy'] )* $ww_005gl ,2)  ;
	    			// 变动成本小计 =  小计 + 税费及财务费用   + 管理费用  
	    			$v['fbdcb'] = $v['fxiaoji'] + $v['fcwfy'] + $v['fglfy'] ;
	    			// 总成本费用
	    			$v['fzcbfy'] =   $v['fbdcb'] + $v['fzhejiu'] ;
    			}
    			
//     			unset($v['fyjdate']);
    			unset($v['fsetzhaunlifeibl']);
    			unset($v['ffaxzl']);
    			unset($v['fzlsfbiaozhun']);
    			unset($v['fzlhuilv']);
    			 
    			unset($v['fisYongjinbl']);
    			unset($v['fisjingneijingwai']);
    			unset($v['fyongjinbl']);
    			unset($v['fyongjinjine']);
    			
    			unset($v['fzhibaoqi']);
    			
    			//其他成本
    			unset($v['ficerryamount']);
    			unset($v['ficerrqamount']);
    			unset($v['fecoegramount']);
    			unset($v['fyouqifeetemp']);
    			//unset($v['fcustomer']);
    			
    			
    			foreach ($v as $k1=>$v1)
    			{
    				if( $v[$k1] ==='.00' ||  $v[$k1] ==='.0000'  ||  $v[$k1] ==='.000' || ($v[$k1]>0 && $v[$k1]<1) ){
    					$v[$k1] = floatval($v1);
    				}
    			}
    			
    		}
    		
    	}
    	
    	
    	showMsg(200,'成功',$result );
    	
    	
    }
    
    /**
    *预算成本   Save 保存
    * @date: 2022年12月23日 下午5:51:33
    * @author: juyi
    */
    public function yuSuanCBSave(Request $request){
//     	$all = $request->all(); 
    	$param = $request ->get('selectedData') ;
    	$opername = $request ->opername ;
    	$FRepKey = $request ->FRepKey ;
    	$CsData =  $this->getSystemProfile(['FSetSFCWGLFY' ,'FSetGLFY','FSetJCJGLFY','FSetJCJSFCWGLFY','FSetJCJLV','FSetChuanjisheBase','FSetHaiWaiTSF' ]);
    	$CSDataTmp = $param ; 
    	$db = 'gz_YbaojiadanCB';
    	if(empty($param)){
    		showMsg(400,'保存数据不能为空');
    	}
    	if($CSDataTmp)
    	{
    		//海外调试费   fsethaiwaitsf
    		$hwtsf = empty($CsData['fsethaiwaitsf'])? 0: $CsData['fsethaiwaitsf'] ;
    		//判断  海外调试服务费 (正式报价) 
    		foreach ($CSDataTmp as $k1 =>$v1)
    		{
    			if($v1['fishwtsf'] == '是' && $hwtsf == 0){
    				showMsg(400, '流水号：'.$v1['fbillno'].' ,业务需求海外调试费选择是，海外调试费参数设置为0，请检查');
    			}
    			
    		}
    	}
    	$ww_005 = $CsData['fsetsfcwglfy'] ;
    	$ww_005gl  = $CsData['fsetglfy'] ;
    	//设置置甲醇机管理费用 (正式报价)
    	$jcj_005gl = $CsData['fsetjcjglfy'] ;
    	//设置甲醇机税费及财务费用比例
    	$jcj_005 = $CsData['fsetjcjsfcwglfy'] ;
    	//增加甲醇机的利润率
    	$jcj_005lv = $CsData['fsetjcjlv'] ;
    	
    	$dataTmp = $param ; 
    	if($dataTmp){
    		foreach ($dataTmp as $k =>&$v)
    		{
    			unset($v['fyjdate']);
    			unset($v['fcustomer']);
    			unset($v['fcustomername']);
    			unset($v['fmodelno']);
    			unset($v['fjsxyno']);
    			unset($v['fishwtsf']);
    		 
    			// 这里 注意 NK 
    			if($v['fchuanjishe'] == 'NK'){
    				//变动部分小计
    				$v['fbdbfxiaoji'] = round($v['fpatentfee'] +$v['fchuanjianf']+$v['fyunfei']+$v['femissionfee']+$v['ftuzhiss']  ,2) ;
//     				dd($v['fchuanjishe'] == 'NK' , $v['fbdbfxiaoji'] , $v['fchuanjianf'] );
    				//项目专项成本小计	fxmzxCB
    				$v['fxmzxcb'] = round($v['fjiazhangcbcg'] +$v['fjiazhangcbjs']+$v['fjiazhangcbqt'] +$v['fscramount']+$v['fegramount']
    						+$v['ficeramount']+$v['fjiachunamount']  +$v['fguanlucbamount'] +$v['fhaiwaitsf']+$v['fyongjin'] +$v['fcbzsfzhibaof']
    						+$v['fscrpfcszs'] +$v['fegrpfcszs']+$v['fgaizaof']+$v['fzengsong']  ,2)  ;
    				
    				//小计  =  项目专项成本小计 + 变动部分小计  + 固定部分小计
    				$v['fxiaoji'] = round($v['fxmzxcb'] + $v['fbdbfxiaoji'] + $v['fgdbfxiaoji'],2) ;
    				
    				//判断是否是甲醇机
    				if( stripos( strtoupper($v['fmodel']) , 'LGIM' ) !== false)    {
    					// 税费及财务费用 = (小计+ 折旧费用 ) *设置置甲醇机管理费用 (正式报价) 0.05
    					$v['fcwfy'] = round(( $v['fxiaoji'] +$v['fzhejiu']) * $jcj_005 ,2);
    					// 管理费用
    					$v['fglfy'] =  round(($v['fxiaoji'] +$v['fzhejiu'] + $v['fcwfy'] )* $jcj_005gl ,2) ;
    					// 变动成本小计 =  小计 + 税费及财务费用   + 管理费用
    					$v['fbdcb'] = $v['fxiaoji'] + $v['fzhejiu'] + $v['fcwfy'] + $v['fglfy'] ;
    					// 总成本费用
    					$v['fzcbfy'] =   round( $v['fbdcb'] * $jcj_005lv ,2) ;
    					
    				}else{
    					// 税费及财务费用 = 小计 *0.05
    					$v['fcwfy'] = round($v['fxiaoji']  * $ww_005 ,2);
    					// 管理费用
    					$v['fglfy'] =  round(($v['fxiaoji'] + $v['fcwfy'] )* $ww_005gl ,2)  ;
    					// 变动成本小计 =  小计 + 税费及财务费用
    					$v['fbdcb'] = $v['fxiaoji'] + $v['fcwfy'] + $v['fglfy'] ;
    					
    					// 总成本费用
    					$v['fzcbfy'] =   $v['fbdcb'] + $v['fzhejiu'] ;
    				}
    				
    			}
    			
    		}
    	}
//     	dd($data) ; 
    	//字符串
    	$fbillno =join("','", array_column($dataTmp, 'fbillno'));
    	$fbillnoStr = "'".$fbillno ."'";
     	//生成 流水号 删掉 
    	$delete = sqlsrv_query($this->SqlServer, "delete from {$db} where  fbillno in ({$fbillnoStr}) ");
    	$data = $dataTmp;
    	$getVexTableColumnData = $this->getVexTableColumn('30002') ;
//     	foreach ($dataTmp as $k =>&$v)
//     	{
//     		foreach ($getVexTableColumnData as $kc=>$vc)
//     		{
//     			if( ( empty($v[$vc['frepfld']]) || $v[$vc['frepfld']] =='.00' ) && $vc['freptype'] == 131 ){
//     				$v[$vc['frepfld']] = 0;
//     			}
//     			if( empty($v[$vc['frepfld']])  && ($vc['freptype'] == 202 || $vc['freptype'] == 200 ) ){
//     				$v[$vc['frepfld']] = '';
//     			}
//     			$data[$k][$vc['frepfld']] = $v[$vc['frepfld']] ;
//     			$data[$k]['fcreatetime'] =  getCurrentTime() ;
//     			unset($data[$k]['fcustomer']);
//     			unset($data[$k]['fcustomername']);
//     			unset($data[$k]['fmodelno']);
//     			unset($data[$k]['fyjdate']);
    			
//     		}
//     	}
    	
    	if(count($data)>400){
    		$each=400;
    		$total =count($data); //数据总数
    		$step=ceil($total/$each); //insert执行总次数
    		$j = 1;
    		$s = $step;
    		foreach ($data as $k=>$v)
    		{
    			$arr0=[];$Tmp0 =[];
    			if($j > $step) break;
    			$arr0 = array_slice($data, ($step - $s) * $each, $each);     // 每次取500条
    			$qkid =SqlServerUtil::sqlsrvAllTosql($this->SqlServer, $db ,$arr0);
    			$j++;
    			$s--;
    		}
    		
    	}else{
    		$qkid =SqlServerUtil::sqlsrvAllTosql($this->SqlServer, $db ,$data);
    		$this->writeLog(getMkName($FRepKey),'删除' , $FRepKey , $data ,$opername);
    	}
     
    	showMsg(200,'保存成功');
    }
    
    
    /**
    *  生成报价单    -- 正式  
    * @date: 2022年12月19日 下午4:47:00
    * @author: juyi
    */
    public function ScBaoJiaDan(Request $request){
    	$fbillno = $request -> fbillno ; 
    	$fmodel = $request -> fmodel ; 
    	$fid =  $request -> fid  ;  
    	$FRepKey = $request ->  FRepKey; 
    	$db = columnBiao($FRepKey);
    	$opername =  $request ->  opername; 
    	//参数值
    	$CsData =  $this->getSystemProfile();
    	//税率
    	$fax = $CsData['fsetffax'].'%'; 
    	$FSetCZBQPrice = $CsData['fsetczbqprice'] ;
    	// 超标准收费质保费用 --- 设置参数  fcbzshzhibaof
    	// 设置参数单价 *  月份（取质保期） /6
    	// v1.fbillno,v1.fid,v1.fmodel,v1.fqty,  这里加账成本 为空
    	// 市场部答复无赠送
    	// 市场部答复无佣金
    	// 市场部答复无加账
    	$sql =" select v1.* , sc.fsjpower ,sc.fhtPower  , sc.fchuanjishe , sc.fcustomer,'{$fax}' as  ftax
		, 0 as fjiazhangje,0 as fzstiaojian, sc.fyunbaof , 0 as  fshoufeizbq, sc.fzlyhAmount as  fzlyouhuibili
		,sc.fzhibaoqi,sc.fyjdate,sc.fcustomername,sc.fmodelno,sc.fjsxyno 	 
		from {$db} v1 left join gz_YBaseSC sc on sc.fbillno = v1.fbillno  
    	where v1.fid = {$fid}  ";
    	 
    	$result1 = SqlServerUtil::execToSql($this->SqlServer, $sql ,2);
    	$result = arraykeyToLower($result1);
    	
    	$sqlnote =" SELECT * FROM  gz_YbaojiadanCB_Note  where fbillno ='{$fbillno}' " ;
    	$result2 = SqlServerUtil::execToSql($this->SqlServer, $sqlnote ,2);
    	//字段列
    	$vxetableConfig = $this->getVxetableConfigData($FRepKey , $opername );
    	$backRes = [];
    	if($vxetableConfig && $result){
    		//超标准收费质保费用 --- 设置参数
    		//设置参数单价 *  月份（取质保期） /6
    		// v1.fbillno,v1.fid,v1.fmodel,v1.fqty,
    		foreach ($vxetableConfig as $conK =>$conV)
    		{
    			$backRes[$conV['frepfld']] = $result[$conV['frepfld']];
    		}
    		if($backRes){
    			foreach ($backRes as $k1=>&$v1)
    			{
    				if( $v1  === '.00' ||  $v1  ==='.0000' ){
    					$v1  = floatval($v1); 
    				}
    			}
    			$backRes['note'] =[
    					'fid' =>0 ,
    					'fbillno' =>$fbillno ,
    					'FStatus' =>0 ,
    					'checkName' =>'' ,
    					'fcreatetime' =>'' ,
    					'fremark' =>'' ,
    					'fmodel' =>$result['fmodel'] ,
    					'funit' =>'' ,
    					'fsjpower' =>'' ,
    					'ftonnage' =>'' ,
    					'ftaxSinglezjcl' =>'' ,
    					'fyouqifee' =>'' ,
    					'ffucaitotal' =>'' ,
    					'fsdtotal' =>'' ,
    					'fsalecost' =>'' ,
    					'fqualitycost' =>'' ,
    					'fweiwaifee' =>'' ,
    					'fdrawingfee' => '按5台分摊' ,
    					'fworkwhole' => '按10台分摊，发运工装不分摊'  ,
    					'fcutter' => '按5台分摊' ,
    					'fzhijierg' =>'' ,
    					'fgdbfxiaoji' =>'' ,
    					'fpatentfee' =>'按照市场部给的交期计算' ,
    					'fchuanjianf' =>'' ,
    					'fyunfei' =>'' ,
    					'femissionfee' =>'按照生效台数'.intval($result['fqty']).'台分摊' ,
    					'ftuzhiss' => '按照生效台数'.intval($result['fqty']).'台分摊' ,
    					'fbdbfxiaoji' =>'' ,
    					'fjiazhangcbcg' =>'见加账清单' ,
    					'fjiazhangcbjs' =>'见加账清单' ,
    					'fjiazhangcbqt' =>'见加账清单' ,
    					'fguanlucbamount' =>'' ,
    					'ficeramount' =>'' ,
    					'fscramount' =>'本项目需要增加的设备费用按需求的生效台数分摊' ,
    					'fegramount' =>'本项目需要增加的设备费用按需求的生效台数分摊' ,
    					'fjiachunamount' =>'' ,
    					'fgaizaof' =>'' ,
    					'fzengsong' =>'' ,
    					'fhaiwaitsf' =>'' ,
    					'fyongjin' =>'' ,
    					'fcbzsfzhibaof' =>'' ,
    					'fxmzxcb' =>'' ,
    					'fxiaoji' =>'' ,
    					'fcwfy' =>'' ,
    					'fglfy' =>'' ,
    					'fbdcb' =>'' ,
    					'fzhejiu' =>'' ,
    					'fzcbfy' =>'' ,
    			];
    			if($result2){
    				$backRes['note']= $result2;
    			}
    			
    		}
    		showMsg(200,'成功' , $backRes);
    	} 
    	showMsg(200,'成功' , $backRes);
    }
    
    
    
    /**
     *  生成报价单    -- 正式 报价    (((  加账    . ,, 后续  )) 
     * @date: 2022年12月19日 下午4:47:00
     * @author: juyi
     */
    public function ScBaoJiaDanJZ(Request $request){
    	$fbillnoentry = $request -> fbillnoentry ;
    	$fbillno = $request -> fbillno ??'' ;
    	$fmodel = $request -> fmodel ;
    	$fid =  $request -> fid  ;
    	$FRepKey = $request ->  FRepKey;
    	$db = columnBiao($FRepKey);
    	$opername =  $request ->  opername;
    	if(empty($fbillnoentry)){
    		showMsg(400,'流水号错误，请检查！') ;
    	}
    	//参数值
    	$CsData =  $this->getSystemProfile();
    	//税率
    	$fax = $CsData['fsetffax'].'%';
    	$FSetCZBQPrice = $CsData['fsetczbqprice'] ;
    	if( in_array($FRepKey, [ '34004',   ])){
    		//正式报价加账 
    		$zsbaojiaNote = 'gz_YbaojiadanCB_NoteJZ' ;
    		$zsbaojiaSC = 'gz_YBaseSC_HXJZ' ;
    	}else{
    		// 30011  正式报价(后续 签订合同)  
    		$zsbaojiaNote = 'gz_YbaojiadanCB_NoteHT' ;
    		$zsbaojiaSC = 'gz_YBaseSC_QDHT' ;
    	}
    	// 超标准收费质保费用 --- 设置参数  fcbzshzhibaof
    	// 设置参数单价 *  月份（取质保期） /6
    	// v1.fbillno,v1.fid,v1.fmodel,v1.fqty,  这里加账成本 为空
    	// 市场部答复无赠送
    	// 市场部答复无佣金
    	// 市场部答复无加账
    	$sql =" select v1.* , sc.fsjpower ,sc.fhtPower  , sc.fchuanjishe , sc.fcustomer,'{$fax}' as  ftax
    	, 0 as fjiazhangje,0 as fzstiaojian, sc.fyunbaof , 0 as  fshoufeizbq, sc.fzlyhAmount as  fzlyouhuibili
    	,sc.fzhibaoqi,sc.fyjdate,sc.fcustomername,sc.fmodelno,sc.fjsxyno
    	from {$db} v1 left join {$zsbaojiaSC} sc on sc.fbillnoentry = v1.fbillnoentry
    	where v1.fid = {$fid}  ";
    	
    	$result1 = SqlServerUtil::execToSql($this->SqlServer, $sql ,2);
    	$result = arraykeyToLower($result1);
    	
    	$sqlnote =" SELECT * FROM  {$zsbaojiaNote}  where fbillnoentry ='{$fbillnoentry}' " ;
    	$result2 = SqlServerUtil::execToSql($this->SqlServer, $sqlnote ,2);
    	//字段列
    	$vxetableConfig = $this->getVxetableConfigData($FRepKey , $opername );
    	$backRes = [];
    	if($vxetableConfig && $result){
    		//超标准收费质保费用 --- 设置参数
    		//设置参数单价 *  月份（取质保期） /6
    		// v1.fbillno,v1.fid,v1.fmodel,v1.fqty,
    		foreach ($vxetableConfig as $conK =>$conV)
    		{
    			$backRes[$conV['frepfld']] = $result[$conV['frepfld']];
    		}
    		if($backRes){
    			foreach ($backRes as $k1=>&$v1)
    			{
    				if( $v1  === '.00' ||  $v1  ==='.0000' ){
    					$v1  = floatval($v1);
    				}
    			}
    			$backRes['note'] =[
    					'fid' =>0 ,
    					'fbillno' =>$fbillno ,
    					'fbillnoentry' =>$fbillnoentry ,
    					
    					'FStatus' =>0 ,
    					'checkName' =>'' ,
    					'fcreatetime' =>'' ,
    					'fremark' =>'' ,
    					'fmodel' =>$result['fmodel'] ,
    					'funit' =>'' ,
    					'fsjpower' =>'' ,
    					'ftonnage' =>'' ,
    					'ftaxSinglezjcl' =>'' ,
    					'fyouqifee' =>'' ,
    					'ffucaitotal' =>'' ,
    					'fsdtotal' =>'' ,
    					'fsalecost' =>'' ,
    					'fqualitycost' =>'' ,
    					'fweiwaifee' =>'' ,
    					'fdrawingfee' => '按5台分摊' ,
    					'fworkwhole' => '按10台分摊，发运工装不分摊'  ,
    					'fcutter' => '按5台分摊' ,
    					'fzhijierg' =>'' ,
    					'fgdbfxiaoji' =>'' ,
    					'fpatentfee' =>'按照市场部给的交期计算' ,
    					'fchuanjianf' =>'' ,
    					'fyunfei' =>'' ,
    					'femissionfee' =>'按照生效台数'.intval($result['fqty']).'台分摊' ,
    					'ftuzhiss' => '按照生效台数'.intval($result['fqty']).'台分摊' ,
    					'fbdbfxiaoji' =>'' ,
    					'fjiazhangcbcg' =>'见加账清单' ,
    					'fjiazhangcbjs' =>'见加账清单' ,
    					'fjiazhangcbqt' =>'见加账清单' ,
    					'fguanlucbamount' =>'' ,
    					'ficeramount' =>'' ,
    					'fscramount' =>'本项目需要增加的设备费用按需求的生效台数分摊' ,
    					'fegramount' =>'本项目需要增加的设备费用按需求的生效台数分摊' ,
    					'fjiachunamount' =>'' ,
    					'fgaizaof' =>'' ,
    					'fzengsong' =>'' ,
    					'fhaiwaitsf' =>'' ,
    					'fyongjin' =>'' ,
    					'fcbzsfzhibaof' =>'' ,
    					'fxmzxcb' =>'' ,
    					'fxiaoji' =>'' ,
    					'fcwfy' =>'' ,
    					'fglfy' =>'' ,
    					'fbdcb' =>'' ,
    					'fzhejiu' =>'' ,
    					'fzcbfy' =>'' ,
    			];
    			if($result2){
    				$backRes['note']= $result2;
    			}
    			
    		}
    		showMsg(200,'成功' , $backRes);
    	}
    	showMsg(200,'成功' , $backRes);
    }
    
    
    
    /**
    * 预算 走流程  ZLC  -- 查询-- 查询-- 查询
    * * 预算 走流程  ZLC
    * * 预算 走流程   ZLC
    * @date: 2023年1月9日 下午3:43:44
    * @author: juyi
    */
    public function yuSuanZLC(Request $request){
    	$keyword = $request->keyword;
    	$fbrand = $request->fbrand;
    	$fsheji = $request->fsheji??0; //设计经营
    	
    	$fzhejiund = $request->fzhejiu??getCurrentTime(10); //折旧年度期间
    	$keywordStr="";
    	if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
    		$keyword =  $request->keyword ;
    		$keywordTmp = explode(',',$keyword);
    		if(count($keywordTmp)>1){
    			$tmpcx = '';
    			foreach ($keywordTmp as $v)
    			{
    				$tmpcx .= " or charindex('{$v}',v1.Fmodel)>0  " ;
    			}
    			$keywordStr=' and ( '.trim($tmpcx,' or') .")";
    		}else{
    			$keywordStr=" and ( charindex('{$keyword}',v1.fmodel)>0   )";
    		}
    		
    	}
    	$fbrandStr="";
    	if ($request->has('fbrand') and $request->fbrand != '' and !empty($request->fbrand)) {
    		$fbrand =  $request->fbrand ;
    		$fbrandStr=" and v1.fbrand = '{$fbrand}'  ";
    	}
    	//油气费非
//     	$sql = " select fbrand,fmodel  from gz_Yyiluf  where fmodel = '{$fmodel}' "  ;
//     	$res=SqlServerUtil::exec1($this->SqlServer, strtolower($sql),2 );
//     	$yiluru = 0;

    	//参数值
    	$CsData =  $this->getSystemProfile();
    	//税率
    	$fax = $CsData['fsetffax']/100;
    	$faxff = $CsData['fsetffax'];
    	//汇率
    	$huilv = $CsData['fsethuilv'];
    	//-气缸单价
    	$qigang = $CsData['fsetqigangprice'];
    	//燃气单价
    	$ranqi = $CsData['fsetranqiprice'];
    	//柴油单价
    	$chaiyou = $CsData['fsetchaiyouprice'];
    	//直接人工 
    	$fhanjiePrice= $CsData['fsetrgjiegoucjprice'];
    	$fjijiaPrice = $CsData['fsetrgjijiacjprice'];
    	$fzhuangshiPrice = $CsData['fsetrgzhuangshicjprice']; 
    	//专利费比例
    	$fsetzhaunlifeibl = $CsData['fsetzhaunlifeibl']; 
    	
    	
    	$zjYear = getCurrentTime(5) ;
    	//专利费
    	$ZlData = SqlServerUtil::execToSql($this->SqlServer, "select * from gz_Yzhuanlif " );
    	
    	//排放检测费
    	$pfjjData = SqlServerUtil::execToSql($this->SqlServer, "select *  from gz_Ypfceshif " );
    	
    	//图纸费
    	$tzData = SqlServerUtil::execToSql($this->SqlServer, "select * from gz_Ytuzhif " );
    	//税率
    	$ww_113 = 1+$fax ;
    	//折旧费
    	$zjData = SqlServerUtil::execToSql($this->SqlServer, "select * from gz_Yzhejiuf where fyear ='{$zjYear}' " ,2);
    	$zhejiuje =0;
    	if(!empty($zjData)){
    		$zhejiuje =  Round($zjData['fcjZjAmount']*$ww_113,2)  ;
    	}
    	//变量 值
    	//委外
    	$ww_103 = $CsData['fsetweiwaif'] ;    	$ww_10000 = $CsData['fsetprodfy'] ;    	
    	$ww_10 = $CsData['fsetprodgzftts'] ;   	$ww_5 = $CsData['fsetprodxhdjftts'] ;
    	//图纸送审
    	$ww_106 = $CsData['fsettuzhiss'] ;
    	//运保费
    	$ww_109 = $CsData['fsetyunbaof'] ;
    	//财务
    	$ww_005 = $CsData['fsetsfcwglfy'] ;
    	$ww_005gl = $CsData['fsetglfy'] ;
    	//设置置甲醇机管理费用 (正式报价)
    	$jcj_005gl = $CsData['fsetjcjglfy'] ;
    	//设置甲醇机税费及财务费用比例
    	$jcj_005 = $CsData['fsetjcjsfcwglfy'] ;
    	//增加甲醇机的利润率
    	$jcj_005lv = $CsData['fsetjcjlv'] ;
    	
    	$cjf_106 = $CsData['fsetchuanjianccs'] ;
    	
    	//走流程生成 
//     	预算 走流程  ZLC
    	$sql ="  select '' as fbillno,  1 as fqty ,
		v1.fmodel ,
		v1.ffuliaopakeage,
    	v1.fbrand,v1.funit ,v1.fpower ,
    	(v1.fhanjiegs + v1.fjijiags + v1.fzhuangshigs ) as fworkhour , v1.fSCRgs as fworkhourScr , v1.fEGRgs as  fworkhourEgr ,
    	Round(isnull( cgcb.fallAmount, 0 )* {$ww_113},2)  as  ftaxSinglezjcl,
    	
    	0 as fPatentfee,
    	Round(isnull(cjccs.fchanjianfeiCCS,0)*{$ww_113},2) as fshipfeeCCS,
    	Round(isnull(cjabs.fchanjianfeiABS,0)*{$ww_113} ,2) as fshipfeeABS,
    	Round(isnull(cjlr.fchanjianfeiLR,0)*{$ww_113} ,2) as fshipfeeLR,
    	Round(isnull(cjbv.fchanjianfeiBV,0)*{$ww_113},2) as fshipfeeBV,
    	Round(isnull(cjnk.fchanjianfeiNK,0)*{$ww_113},2) as fshipfeeNK,
    	Round(isnull(cjdnv.fchanjianfeiDNV,0)*{$ww_113},2)  as fshipfeeDNVGL,
    	
    	(isnull(v1.fdieselOil,0)* $chaiyou +  isnull(v1.fGas,0)*$ranqi +  isnull(v1.fCylinderoil,0)*$qigang)*{$ww_113}  as fyouqifee,
    	
		0 as  femissionfee,
    	0 as fDrawingfee,
    	isnull(zlcb.fallAmount,0) as fqualityCost,
    	Round((isnull(prod.fweiwaiAmount,0)*{$ww_10000}/{$ww_103})* $ww_113 ,2) as fweiwaifee,
    	round(((prod.fhanjiegz +prod.fjijiagz +prod.fzhuangshigz +prod.fshichegz)/{$ww_10} +prod.ffayungzzj)*{$ww_10000},2)  as fworkwhole,
		round(((prod.fhanjiegz +prod.fjijiagz +prod.fzhuangshigz +prod.fshichegz)/{$ww_10} +prod.ffayungzfd)*{$ww_10000},2)  as fworkparted,
    	Round(isnull(prod.fxjxtsdaoju,0)*{$ww_10000}/{$ww_5} ,2)  as fcutter ,
    	
    	Round(isnull(fjhj.fallamount ,0)*{$ww_113},2) as fweldWorkfc ,
    	Round(isnull(fjjj.fallamount ,0) ,2) as fmachineWorkfc,
    	Round(isnull(fjzs.fallamount ,0)*{$ww_113},2) as  ftestWorkfc,
    	0 as ffucaitotal,
    	
    	Round(isnull(sd.fjgcjDWAmount,0) + isnull(sd.fhanjiecj,0) ,2) as  fweldWorksd ,
    	Round(isnull(sd.fjijiacj,0),2)  as  fmachineWorksd ,
    	Round(isnull(sd.fzhuangshicj,0),2)  as ftestWorksd ,
    	0  as fsdTotal,
    	
    	Round(isnull(v1.ftuzhissCCS,0) *{$ww_113},2) as fDrawingCCS ,
    	Round(isnull(v1.ftuzhissABS,0) *{$ww_113} ,2) as fDrawingABS ,
    	Round(isnull(v1.ftuzhissLR,0) *{$ww_113} ,2) as fDrawingLR ,
    	Round(isnull(v1.ftuzhissBV,0) *{$ww_113} ,2) as fDrawingBV ,
    	Round(isnull(v1.ftuzhissNK,0) *{$ww_113} ,2) as fDrawingNK ,
    	Round(isnull(v1.ftuzhissDNVGL,0) *{$ww_113} ,2) as fDrawingDNVGL ,
    	
		isnull(v1.fniuzhenRMB,0)  AS fniuzhenjisuanfee,
		Round(isnull(yb.fallAmount,0)/{$ww_109}*{$ww_113},2) AS fyunfei,
    	isnull(shts.fallAmount,0) as fsaleCost ,
		
		0 as fsczlCost ,
		Round(v1.fhanjiegs *$fhanjiePrice*{$ww_113},2)  as fweldRg ,
		Round(v1.fjijiags * $fjijiaPrice*{$ww_113},2)  as fjjgRg ,
		Round(v1.fzhuangshigs * $fzhuangshiPrice*{$ww_113},2) as fzhuangshiRg ,
		0 as fzhijieRg ,

		{$zhejiuje} as fzhejiu ,
    	0  as fSCRCost ,
    	0  as fEGRCost ,

    	0 as fscrIncWork ,
    	0 as fscrIncSD ,
    	0 as fNooneyouqifee,
    	
    	0 as fsingleProdCostCCS ,0 as fsingleProdCostABS ,0 as fsingleProdCostLR ,0 as fsingleProdCostDNVGL ,0 as fsingleProdCostBV ,0 as fsingleProdCostNK  ,
		0 as fcwsingleProdCostCCS ,0 as fcwsingleProdCostABS ,0 as fcwsingleProdCostLR ,0 as fcwsingleProdCostDNVGL ,0 as fcwsingleProdCostBV ,0 as fcwsingleProdCostNK     	
		
		from
    	gz_YBaseJS v1 
    	inner JOIN (SELECT SUM(fallAmount ) fallAmount, fprodno FROM gz_Ycaigoucbf GROUP BY fprodno) cgcb on cgcb.fprodno = v1.fmodel
    	inner JOIN gz_YchuanjianfCCS  cjccs on cjccs.fmodel= v1.fmodel   and  cjccs.fchuanjishe = 'CCS'
    	inner JOIN gz_YchuanjianfABS  cjabs on cjabs.fmodel= v1.fmodel   and   cjabs.fchuanjishe = 'ABS'
    	inner JOIN gz_YchuanjianfLR  cjlr on cjlr.fmodel= v1.fmodel   and  cjlr.fchuanjishe = 'LR'
    	inner JOIN gz_YchuanjianfBV  cjbv on cjbv.fmodel= v1.fmodel   and  cjbv.fchuanjishe = 'BV'
    	left JOIN gz_YchuanjianfNK  cjnk on cjnk.fmodel= v1.fmodel   and  cjnk.fchuanjishe = 'NK'
    	inner JOIN gz_YchuanjianfDNV  cjdnv on cjdnv.fmodel= v1.fmodel   and  cjdnv.fchuanjishe = 'DNV'
    	
    	inner join gz_Yzhiliangcb zlcb on zlcb.fmodel = v1.fmodel
    	inner join gz_YBaseProduce prod on prod.fmodel = v1.fmodel
    	
    	inner join gz_Yfucaicbf  fjhj on fjhj.fmodel = v1.fmodel
    	inner join gz_Yfucaicbfjijia  fjjj on fjjj.fmodel = v1.fmodel
    	inner join gz_Yfucaicbfzshi fjzs on fjzs.fmodel = v1.fmodel
    	
    	inner join gz_Yshuidianf sd on sd.fmodel = v1.fmodel
    	inner join gz_Yyunbaof yb on yb.fmodel = v1.fmodel
    	inner join gz_Yshtswhcb shts on shts.fmodel = v1.fmodel
    	where 1=1 and v1.fstatus = 1 {$keywordStr} {$fbrandStr} ";
    	//  and v1.fmodel not in ( select fmodel from gz_YbaojiadanZLC where  FStatus =1)
    	//预算 走流程  ZLC 
//   echo $sql;die;
    	$res = SqlServerUtil::execToSql($this->SqlServer, $sql );
    	$result =[];
//     	dd($res);
    	if($res ){
    		$result = arraykeyToLower($res);
    		foreach ($result as $k =>&$v)
    		{
    			//专利费
//     			dd($v['fpower'],$v['fbrand'], getZLValue( $ZlData  ,$v['fmodel'],$v['fpower'],$v['fbrand'] ,$faxff ) ,$faxff);
    			$v['fpatentfee'] = getZLValue( $ZlData  ,$v['fmodel'],$v['fpower'],$v['fbrand'] ,$faxff )* $fsetzhaunlifeibl ;
    			
    			//图纸费
    			$v['fdrawingfee'] = round(( $this->getTZValue( $tzData  ,$v['fmodel'] , $v['fbrand']  )) * $ww_113/5 ,2) ;
    			//排放测试费
    			$v['femissionfee'] = getPfjjValue( $pfjjData  ,$v['fmodel']  ) * $ww_113 ;
    			//辅材合计
    			$v['ffucaitotal'] = $v['fweldworkfc'] + $v['fmachineworkfc'] + $v['ftestworkfc'] ;
    			//水电合计
    			$v['fsdtotal'] = $v['fweldworksd'] + $v['fmachineworksd'] + $v['ftestworksd'] ;
    			//直接人工成本
    			$v['fzhijierg'] = $v['fweldrg'] + $v['fjjgrg'] + $v['fzhuangshirg'] ;
    			
//     			dd(  $v['ftaxsinglezjcl']  );
    			//整体单台产品成本（ccs)
    			$v['fsingleprodcostccs'] = $v['ftaxsinglezjcl']+ $v['fpatentfee']+ $v['fshipfeeccs']+ $v['fyouqifee']
    			+ $v['femissionfee']+ $v['fdrawingfee']+ $v['fqualitycost']+ $v['fweiwaifee']+ $v['fworkwhole']
    			+ $v['fcutter']+ $v['ffucaitotal']+ $v['fsdtotal']+ $v['fdrawingccs'] 
    			+ $v['fyunfei']+ $v['fsalecost']+ $v['fzhijierg']   ;
    		
    			//     			dd($v['fsingleprodcostccs'] , $v['ftaxSinglezjcl'],$v['fpatentfee'],$v['fshipfeeccs'],$v['fyouqifee']
//     					,$v['femissionfee'],$v['fdrawingfee'],$v['fqualitycost'],$v['fweiwaifee'],$v['fworkwhole']
//     					,$v['fcutter'],$v['ffucaitotal'],$v['fsdtotal'],$v['fdrawingccs'],$v['fniuzhenjisuanfee']
//     					,$v['fyunfei'],$v['fsalecost'],$v['fzhijierg']);
    			//整体单台产品成本（abs)
    			$v['fsingleprodcostabs'] =  $v['ftaxsinglezjcl']+ $v['fpatentfee']+ $v['fshipfeeabs']+ $v['fyouqifee']
    			+ $v['femissionfee']+ $v['fdrawingfee']+ $v['fqualitycost']+ $v['fweiwaifee']+ $v['fworkwhole']
    			+ $v['fcutter']+ $v['ffucaitotal']+ $v['fsdtotal']+ $v['fdrawingabs'] 
    			+ $v['fyunfei']+ $v['fsalecost']+ $v['fzhijierg']   ;
    			//整体单台产品成本（lr)
    			$v['fsingleprodcostlr'] = $v['ftaxsinglezjcl']+ $v['fpatentfee']+ $v['fshipfeelr']+ $v['fyouqifee']
    			+ $v['femissionfee']+ $v['fdrawingfee']+ $v['fqualitycost']+ $v['fweiwaifee']+ $v['fworkwhole']
    			+ $v['fcutter']+ $v['ffucaitotal']+ $v['fsdtotal']+ $v['fdrawinglr'] 
    			+ $v['fyunfei']+ $v['fsalecost']+ $v['fzhijierg']  ;
    			//整体单台产品成本（dnv)
    			$v['fsingleprodcostdnvgl'] = $v['ftaxsinglezjcl']+ $v['fpatentfee']+ $v['fshipfeednvgl']+ $v['fyouqifee']
    			+ $v['femissionfee']+ $v['fdrawingfee']+ $v['fqualitycost']+ $v['fweiwaifee']+ $v['fworkwhole']
    			+ $v['fcutter']+ $v['ffucaitotal']+ $v['fsdtotal']+ $v['fdrawingdnvgl'] 
    			+ $v['fyunfei']+ $v['fsalecost']+ $v['fzhijierg'] ;
    			//整体单台产品成本（bv)
    			$v['fsingleprodcostbv'] = $v['ftaxsinglezjcl']+ $v['fpatentfee']+ $v['fshipfeebv']+ $v['fyouqifee']
    			+ $v['femissionfee']+ $v['fdrawingfee']+ $v['fqualitycost']+ $v['fweiwaifee']+ $v['fworkwhole']
    			+ $v['fcutter']+ $v['ffucaitotal']+ $v['fsdtotal']+ $v['fdrawingbv'] 
    			+ $v['fyunfei']+ $v['fsalecost']+ $v['fzhijierg'] ;
    			//整体单台产品成本 nk
    			$v['fsingleprodcostnk'] =  $v['ftaxsinglezjcl']+ $v['fpatentfee']+ $v['fshipfeenk']+ $v['fyouqifee']
    			+ $v['femissionfee']+ $v['fdrawingfee']+ $v['fqualitycost']+ $v['fweiwaifee']+ $v['fworkwhole']
    			+ $v['fcutter']+ $v['ffucaitotal']+ $v['fsdtotal']+ $v['fdrawingnk'] 
    			+ $v['fyunfei']+ $v['fsalecost']+ $v['fzhijierg'] ;
    			
    			//税费及财务费用   = 整体单台产品成本（ccs)  *5% 
    			//整体单台产品成本（ccs)
    			$v['fcwsingleprodcostccs'] = $v['fsingleprodcostccs'] *$ww_005 ;
    			//整体单台产品成本（abs)
    			$v['fcwsingleprodcostabs'] =  $v['fsingleprodcostabs'] *$ww_005 ;
    			//整体单台产品成本（lr)
    			$v['fcwsingleprodcostlr'] = $v['fsingleprodcostlr'] *$ww_005 ;
    			//整体单台产品成本（dnv)
    			$v['fcwsingleprodcostdnvgl'] = $v['fsingleprodcostdnvgl'] *$ww_005 ;
    			//整体单台产品成本（bv)
    			$v['fcwsingleprodcostbv'] =$v['fsingleprodcostbv'] *$ww_005 ;
    			//整体单台产品成本 nk
    			$v['fcwsingleprodcostnk'] =  $v['fsingleprodcostnk'] *$ww_005 ;
    			
    			// 管理费用  =   5% *( 税费及财务费用 + css )
    			$v['fglfyccs'] =  ($v['fsingleprodcostccs'] + $v['fcwsingleprodcostccs']) *$ww_005gl ;
    			$v['fglfyabs'] =   ($v['fsingleprodcostabs'] + $v['fcwsingleprodcostabs']) *$ww_005gl ;
    			$v['fglfylr'] =   ($v['fsingleprodcostlr'] + $v['fcwsingleprodcostlr']) *$ww_005gl ;
    			$v['fglfydnv'] =   ($v['fsingleprodcostdnvgl'] + $v['fcwsingleprodcostdnvgl']) *$ww_005gl ;
    			$v['fglfybv'] =   ($v['fsingleprodcostbv'] + $v['fcwsingleprodcostbv']) *$ww_005gl ;
    			$v['fglfynk'] =   ($v['fsingleprodcostnk'] + $v['fcwsingleprodcostnk']) *$ww_005gl ;
    			
    			//变动成本小计 = 小计（css） + 税费及财务费用 + 管理费用 ；
    			$v['fbdcbccs'] =  $v['fsingleprodcostccs'] + $v['fcwsingleprodcostccs'] + $v['fglfyccs'] ;
    			$v['fbdcbabs'] =  $v['fsingleprodcostabs'] + $v['fcwsingleprodcostabs'] + $v['fglfyabs'] ;
    			$v['fbdcblr'] =  $v['fsingleprodcostlr'] + $v['fcwsingleprodcostlr'] + $v['fglfylr'] ;
    			$v['fbdcbdnv'] =  $v['fsingleprodcostdnvgl'] + $v['fcwsingleprodcostdnvgl'] + $v['fglfydnv'] ;
    			$v['fbdcbbv'] =  $v['fsingleprodcostbv'] + $v['fcwsingleprodcostbv'] + $v['fglfybv'] ;
    			$v['fbdcbnk'] =  $v['fsingleprodcostnk'] + $v['fcwsingleprodcostnk'] + $v['fglfynk'] ;
    			
    			//总成本费用  =  变动成本小计 + 折旧 
    			$v['fzcbfyccs'] =  $v['fbdcbccs']  +  $v['fzhejiu']  ;
    			$v['fzcbfyabs'] =  $v['fbdcbabs']  +  $v['fzhejiu']   ;
    			$v['fzcbfylr'] =   $v['fbdcblr']  +  $v['fzhejiu']   ;
    			$v['fzcbfydnv'] =  $v['fbdcbdnv']  +  $v['fzhejiu']   ;
    			$v['fzcbfybv'] =   $v['fbdcbbv']  +  $v['fzhejiu']   ;
    			$v['fzcbfynk'] =   $v['fbdcbnk']  +  $v['fzhejiu']   ;
    			
    			foreach ($v as $k1=>$v1)
    			{
    				if( $v[$k1] ==='.00' ||  $v[$k1] ==='.0000' ||  $v[$k1] ==='.000' || ($v[$k1]>0 && $v[$k1]<1) ){
    					$v[$k1] = floatval($v1);
    				}
    			}
    			
    		}
    		
    	}
 
    	showMsg(200,'成功',$result );
    	
    }
    
    /**
     * 走流程   Save 保存  -- 只做查询 保存  
     * @date: 2022年12月23日 下午5:51:33
     * @author: juyi
     */
    public function yuSuanZLCSave(Request $request){
    	$param = $request ->get('selectedData') ;
    	$opername = $request ->opername ;
    	$FRepKey = $request ->FRepKey ;
    	if($FRepKey == 30009){
    		$db ="gz_YbaojiadanZLCXC";
    	}else{
    		$db = 'gz_YbaojiadanZLC'; //30004
    	}
    	if(empty($param)){
    		showMsg(400,'保存数据不能为空');
    	}
    	 
    	$data = $param ;
    	//字符串
    	$fmodel =join("','", array_column($data, 'fmodel'));
    	$fmodelStr = "'".$fmodel ."'";
    	
    	$delete = sqlsrv_query($this->SqlServer, "delete from {$db} where  fmodel in ({$fmodelStr}) ");
    	
    	if(count($data)>400){
    		$each=400;
    		$total =count($data); //数据总数
    		$step=ceil($total/$each); //insert执行总次数
    		$j = 1;
    		$s = $step;
    		foreach ($data as $k=>$v)
    		{
    			$arr0=[];$Tmp0 =[];
    			if($j > $step) break;
    			$arr0 = array_slice($data, ($step - $s) * $each, $each);     // 每次取500条
    			 
    			$qkid =SqlServerUtil::sqlsrvAllTosql($this->SqlServer, $db ,$arr0);
    			$j++;
    			$s--;
    		}
    		
    	}else{
    		$qkid =SqlServerUtil::sqlsrvAllTosql($this->SqlServer, $db ,$data);
    		$this->writeLog(getMkName($FRepKey),'删除' , $FRepKey , $data ,$opername);
    	}
    	
    	showMsg(200,'保存成功');
    }
    
    /**
    * 走流程  -- 报价单
    * @date: 2023年1月9日 下午6:57:58
    * @author: juyi
    */
    public function ScBaoJiaDanZLC(Request $request){
    	$fbillno = $request -> fbillno ;
    	$fmodel = $request -> fmodel ;
    	$fid =  $request -> fid  ;
    	$FRepKey = $request ->FRepKey ;
    	$db = columnBiao($FRepKey);
    	$opername = $request ->opername;
    	//参数值
    	$CsData =  $this->getSystemProfile();
    	//税率
    	$fax = $CsData['fsetffax'].'%';
    	 
    	//字段列
    	$vxetableConfig = $this->getVxetableConfigData($FRepKey , $opername );
    	$sql =" select v1.* ,
    	sc.fsjpower ,sc.fhtPower  , sc.fchuanjishe , sc.fcustomer,'{$fax}' as  ftax,
    	0 as fjiazhangje,0 as fzstiaojian,0 as fyongjin,
    	0 as  fshoufeizbq, 0 as  fzlyouhuibili, 0 as fjiazhangcb
    	from {$db} v1
    	left join gz_YBaseJS_BAOJIA js on js.fmodel = v1.fmodel and v1.fbillno = js.fbillno
    	left join gz_YBasesc sc on sc.fmodel = v1.fmodel and v1.fbillno = sc.fbillno
    	where v1.fid = {$fid}  ";
//     	echo $sql;die; 
    	$result =[];
    	$result1 = SqlServerUtil::execToSql($this->SqlServer, $sql ,2);
    	$result = arraykeyToLower($result1);
    	$backRes = [];
    	if($vxetableConfig){
    		//超标准收费质保费用 --- 设置参数
    		//设置参数单价 *  月份（取质保期） /6
    		// v1.fbillno,v1.fid,v1.fmodel,v1.fqty,
    		foreach ($vxetableConfig as $conK =>$conV)
    		{
    			$backRes[$conV['frepfld']] = $result[$conV['frepfld']];
    			$backRes['ftax'] = $result['ftax'];
    		}
//     		dd(111 , $vxetableConfig);
    		if($backRes){
    			foreach ($backRes as $k1=>&$v1)
    			{
    				if( $v1  === '.00' ||  $v1  ==='.0000' ){
    					$v1  = floatval($v1);
    				}
    			}
    		}
    		showMsg(200,'成功' , $backRes);
    		
    	} 
    	showMsg(200,'成功' , $backRes);
    }
    
    
  /**
  * 走流程 机型确认 
  * @date: 2023年2月17日 下午4:10:57
  * @author: juyi
  */
    public function zlcJXQR(Request $request){
    	$FRepKey = $request->get('FRepKey');
    	$opername = $request->get('opername');
    	
    	$FIDStr='';
    	if ($request->has('fid') and $request->fid != '' and !empty($request->fid)) {
    		$FID = $request->fid;
    		$FIDStr=" and fid in ($FID) ";
    	}
    	$fisqr = $request ->fisqr??0;
    	$getMkName =  '已确认' ;
    	$db = columnBiao($FRepKey);
    	
    	$jsname ='技术'.$getMkName ;
    	$cgname ='采购'.$getMkName ;
    	$cwname ='财务'.$getMkName ;
    	$data = $request ->get('data')  ;
    	$time =getCurrentTime();
    	$checkStr = '或未审核 ';
    	if($data){
    		foreach ($data as $k =>$v)
    		{
    			if($v['fisqrname']>0){
    				showMsg(400,'已完成，无法确认！');
    			}
    			
    			if($fisqr == 1){
    				//确认
    				if($FRepKey == '30005'){
    					//技术部
    					$sql="update {$db} set  fisqr = 1, fjishuRemark = '{$jsname}',fcreatetimejs ='{$time}',opernameJS ='{$opername}'  where 1=1 {$FIDStr}   ";
    					$sql1 = " select * from gz_YBaseJS where 1=1 and fmodel = '{$v['fmodel']}' and fstatus =1 " ;
    					$resJS = SqlServerUtil::execToSql($this->SqlServer, $sql1 );
    					if(empty($resJS)){
    						showMsg(400,'当前业务流水号: '.$v['fbillno'].'，技术中心没有这个机型 '.$checkStr.'，请检查。');
    					}
    					//参数设置
    					$csSetData = $this->getSystemProfile(['FSetRGjiegouCJPrice','FSetRGjijiaCJPrice','FSetRGzhuangshiCJPrice']);
    					
    					if($resJS){
    						foreach ($resJS as $kjs =>$vjs)
    						{
    							unset($resJS[$kjs]['fid']);
    							unset($resJS[$kjs]['fcreatetime']);
    							
    							$resJS[$kjs]['fjybjbillno'] = $v['fbillno'];
    							$resJS[$kjs]['fhanjieprice'] = $csSetData['fsetrgjiegoucjprice'];
    							$resJS[$kjs]['fjijiaprice'] = $csSetData['fsetrgjijiacjprice'];
    							$resJS[$kjs]['fzhuangshiprice'] = $csSetData['fsetrgzhuangshicjprice'];
    							
    							if($v['fisqr'] >1   ||  !empty($v['fcaigouremark']) )
    							{
    								showMsg(400,'采购部 、财务部已确认，无法确认！');
    							}
    						}
//     						dd($resJS);
    						SqlServerUtil::sqlsrvDelete($this->SqlServer,'gz_YBaseJS_ZLCCG' , ['fjybjbillno'=> "'".$v['fbillno']."'" ],true);
    						SqlServerUtil::sqlsrvAllTosql($this->SqlServer ,'gz_YBaseJS_ZLCCG' , $resJS);
    					} 
    					
    				}
    				
    				if($FRepKey == '30006'){
    					//采购部
    					$sql="update {$db} set  fisqr = 2, fcaigouRemark = '{$cgname}' ,fcreatetimecg ='{$time}',opernameCG ='{$opername}'   where 1=1 {$FIDStr}   ";
    					
    					$sql1 = " select v1.* from gz_Ycaigoucbf v1   where 1=1 and v1.fprodno = '{$v['fmodel']}' and fstatus =1  " ;
    					$resCG = SqlServerUtil::execToSql($this->SqlServer, $sql1 );
    					if(empty($resCG)){
    						showMsg(400,'采购成本 没有导入这个机型：'.$v['fmodel'].'，'.$checkStr.'请检查');
    					}
    					if($resCG){
    						foreach ($resCG as $kjs =>$vjs)
    						{
    							unset($resCG[$kjs]['fid']);
    							unset($resCG[$kjs]['fcreatetime']);
    							
    							$resCG[$kjs]['fjybjbillno'] = $v['fbillno'];
    							if($v['fisqr'] >2   ||  !empty($v['fcaigouremark']) )
    							{
    								showMsg(400,'财务部已确认，无法确认！');
    							}
    							
    						}
    						    					
    						SqlServerUtil::sqlsrvDelete($this->SqlServer,'gz_Ycaigoucbf_ZLCCG' , ['fjybjbillno'=> "'".$v['fbillno']."'" ],true);
    						SqlServerUtil::sqlsrvAllTosql($this->SqlServer ,'gz_Ycaigoucbf_ZLCCG' , $resCG);
    					}
    					
    				}
    				
    				if($FRepKey == '30007'){
    					// 判断其他部门 是否 已确认
    					foreach ($data as $k =>$v)
    					{
    						if($v['fisqr'] <1  || empty($v['fjishuremark']) ||  empty($v['fcaigouremark']) )
    						{
    							showMsg(400,'采购或技术部门还没有确认！');
    						}
    						$resJYQR  = SqlServerUtil::execToSql($this->SqlServer, "select fbillno,fstatus  from gz_YbaojiadanZLC where fbillno ='{$v['fbillno']}'   ",2 );
    						if($resJYQR){
    							//判断是否有值
    							if($resJYQR['fstatus']>0){
    								showMsg(400,$v['fbillno'].'经营报价已审核，无法再确认');
    							}
    							showMsg(400,$v['fbillno'].'经营报价已生成 ');
    						}
    					}
    					
    					//专利费
    					$ZlData = SqlServerUtil::execToSql($this->SqlServer, "select * from gz_Yzhuanlif where fstatus =1 " );
    					if(empty($ZlData)){
    						showMsg(400,'专利费没有数据或未审核，请检查');
    					}
    					//排放检测费
    					$pfjjData = SqlServerUtil::execToSql($this->SqlServer, "select *  from gz_Ypfceshif where fstatus =1 " );
    					if(empty($pfjjData)){
    						showMsg(400,'排放检测费没有数据或未审核，请检查');
    					}
    					//图纸费
    					$tzData = SqlServerUtil::execToSql($this->SqlServer, "select * from gz_Ytuzhif where fstatus =1 " );
    					if(empty($tzData)){
    						showMsg(400,'图纸费没有数据或未审核，请检查');
    					}
    					//技术部门
    					$jsData = SqlServerUtil::execToSql($this->SqlServer, "select * from gz_YBaseJS where fmodel ='{$v['fmodel']}' ",2 );
    					//参数设置
    					$csSetData = $this->getSystemProfile();
    					
    					foreach ($data as $k =>$v)
    					{
    						//专利确认   getZLValueQR
    						$zlTemp  = getZLValueQR($ZlData ,$v['fmodel'],$v['fbrand'],$v['fbillno'],$csSetData['fsetzhaunlifeibl'], $csSetData['fsetzhaunlifeiblman'],$csSetData['fsetffax'] );
    						
    						if(empty($zlTemp)){
    							showMsg(400,  '专利费数据为空，请检查');
    						}
    						if($zlTemp){
    							SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_Yzhuanlif_ZLCCG' , ['fjybjbillno'=> "'".$v['fbillno']."'" ],true);
    							SqlServerUtil::sqlsrvCreate($this->SqlServer ,'gz_Yzhuanlif_ZLCCG' , $zlTemp);
    						}
    						//排放测试费   getPfjjValueQR
    						$pfcsTemp  = getPfjjValueQR($pfjjData ,$v['fmodel'],$v['fbillno']);
    						if(empty($pfcsTemp)){
    							showMsg(400,  '排放测试费数据为空，请检查');
    						}
    						if($pfcsTemp){
    							SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_Ypfceshif_ZLCCG' , ['fjybjbillno'=> "'".$v['fbillno']."'" ],true);
    							SqlServerUtil::sqlsrvCreate($this->SqlServer ,'gz_Ypfceshif_ZLCCG' , $pfcsTemp);
    						}
    						
    						//图纸费  getTZValueQR
    						$tzTemp = $this->getTZValueQR($tzData  ,$v['fmodel'],$v['fbrand'],$v['fbillno']);
    						if($tzTemp){
    							SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_Ytuzhif_ZLCCG' , ['fjybjbillno'=> "'".$v['fbillno']."'" ],true);
    							SqlServerUtil::sqlsrvCreate($this->SqlServer ,'gz_Ytuzhif_ZLCCG' , $tzTemp);
    						}
    						//折旧 --暂时不判断
    						$zjTemp = $this->getzhejiuQR($v['fbillno'] );
    						if(empty($zjTemp)){
    							showMsg(400, ' 折旧费 本年度没有数据 ，'.$checkStr.'，请检查');
    						}
    						if($zjTemp){
    							SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_Yzhejiuf_ZLCCG' , ['fjybjbillno'=> "'".$v['fbillno']."'" ],true);
    							SqlServerUtil::sqlsrvCreate($this->SqlServer ,'gz_Yzhejiuf_ZLCCG' , $zjTemp);
    						}
    						
    						//船检费CCS	船检费ABS	船检费LR	船检费DNV-GL	船检费BV	船检费NK	
    						$CCSTmep  = $this->getChuanjianQR($v['fmodel'],'26002',$v['fbillno'] );
    						if(empty($CCSTmep)){
    							showMsg(400, '船检费CCS ,机型'.$v['fmodel'].'数据为空 '.$checkStr.'，请检查');
    						}
    						if($CCSTmep){
    							SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_YchuanjianfCCS_ZLCCG' , ['fjybjbillno'=> "'".$v['fbillno']."'" ],true);
    							SqlServerUtil::sqlsrvCreate($this->SqlServer ,'gz_YchuanjianfCCS_ZLCCG' , $CCSTmep);
    						}
    						$ABSTmep  = $this->getChuanjianQR($v['fmodel'],'25002',$v['fbillno'] );
    						if(empty($ABSTmep)){
    							showMsg(400,  '船检费ABS,机型'.$v['fmodel'].'数据为空 '.$checkStr.'，请检查');
    						}
    						if($ABSTmep){
    							SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_YchuanjianfABS_ZLCCG' , ['fjybjbillno'=> "'".$v['fbillno']."'" ],true);
    							SqlServerUtil::sqlsrvCreate($this->SqlServer ,'gz_YchuanjianfABS_ZLCCG' , $ABSTmep);
    						}
    						$LRTmep  = $this->getChuanjianQR($v['fmodel'],'25003',$v['fbillno'] );
    						if(empty($LRTmep)){
    							showMsg(400, '船检费LR ,机型'.$v['fmodel'].'数据为空 '.$checkStr.'，请检查');
    						}
    						if($LRTmep){
    							SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_YchuanjianfLR_ZLCCG' , ['fjybjbillno'=> "'".$v['fbillno']."'" ],true);
    							SqlServerUtil::sqlsrvCreate($this->SqlServer ,'gz_YchuanjianfLR_ZLCCG' , $LRTmep);
    						}
    						$BVTmep = $this->getChuanjianQR($v['fmodel'],'25004',$v['fbillno'] );
    						if(empty($BVTmep)){
    							showMsg(400, '船检费BV ,机型'.$v['fmodel'].'数据为空 '.$checkStr.'，请检查');
    						}
    						if($BVTmep){
    							SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_YchuanjianfBV_ZLCCG' , ['fjybjbillno'=> "'".$v['fbillno']."'" ],true);
    							SqlServerUtil::sqlsrvCreate($this->SqlServer ,'gz_YchuanjianfBV_ZLCCG' , $BVTmep);
    						}
    						$DNVTmep = $this->getChuanjianQR($v['fmodel'],'25005',$v['fbillno'] );
    						if(empty($DNVTmep)){
    							showMsg(400, '船检费DNV ,机型'.$v['fmodel'].'数据为空 '.$checkStr.'，请检查');
    						}
    						if($DNVTmep){
    							SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_YchuanjianfDNV_ZLCCG' , ['fjybjbillno'=> "'".$v['fbillno']."'" ],true);
    							SqlServerUtil::sqlsrvCreate($this->SqlServer ,'gz_YchuanjianfDNV_ZLCCG' , $DNVTmep);
    						}
    						
    						//油气费  == 涉及到 参数设置问题
    						$yqTemp = [
    								'fjybjbillno' => $v['fbillno'] ,
    								'fbrand'=>strtoupper(str_replace(' ','',$v['fbrand'])),
    								'fprodno'=>$v['fmodel'],
    								'funit' =>'',
    								'FdieselOilQty'=> $jsData['fdieselOil'],
    								'fprice'=>$csSetData['fsetchaiyouprice'],
    								'fCylinderoil'=>$jsData['fCylinderoil'],
    								'fCylinderoilPrice' =>$csSetData['fsetqigangprice'],
    								'fgasQty'=>$jsData['fGas'],
    								'fgasPrice'=>$csSetData['fsetranqiprice'],
    								'fAllamount'=> round($jsData['fdieselOil'] *$csSetData['fsetchaiyouprice'] +$jsData['fCylinderoil']*$csSetData['fsetqigangprice'] + $jsData['fGas']*$csSetData['fsetranqiprice'] ),
    						]; 
    						if($yqTemp){
    							SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_Yyouqif_ZLCCG' , ['fjybjbillno'=> "'".$v['fbillno']."'" ],true);
    							SqlServerUtil::sqlsrvCreate($this->SqlServer ,'gz_Yyouqif_ZLCCG' , $yqTemp);
    						}
    						
    						// 质量成本 26013
    						$zhiliangTemp = $this->getjixingQR($v['fmodel'],'26013',$v['fbillno']);
    						if(empty($zhiliangTemp)){
    							showMsg(400, '质量成本 ,机型'.$v['fmodel'].'数据为空 '.$checkStr.'，请检查');
    						}
    						if($zhiliangTemp){
    							SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_Yzhiliangcb_ZLCCG' , ['fjybjbillno'=> "'".$v['fbillno']."'" ],true);
    							SqlServerUtil::sqlsrvCreate($this->SqlServer ,'gz_Yzhiliangcb_ZLCCG' , $zhiliangTemp);
    						}
    						//焊接车间(辅材)
    						$hjcjTemp = $this->getjixingQR($v['fmodel'],' 26008',$v['fbillno']);
    						if(empty($hjcjTemp)){
    							showMsg(400,  '焊接车间(辅材) ,机型'.$v['fmodel'].'数据为空 '.$checkStr.'，请检查');
    						}
    						if($hjcjTemp){
    							SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_Yfucaicbf_ZLCCG' , ['fjybjbillno'=> "'".$v['fbillno']."'" ],true);
    							SqlServerUtil::sqlsrvCreate($this->SqlServer ,'gz_Yfucaicbf_ZLCCG' , $hjcjTemp);
    						}
    						//机加工车间(辅材)
    						$jjgcjTemp = $this->getjixingQR($v['fmodel'],'28006',$v['fbillno']);
    						if(empty($jjgcjTemp)){
    							showMsg(400,  '机加工车间(辅材) ,机型'.$v['fmodel'].'数据为空 '.$checkStr.'，请检查');
    						}
    						if($jjgcjTemp){
    							SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_Yfucaicbfjijia_ZLCCG' , ['fjybjbillno'=> "'".$v['fbillno']."'" ],true);
    							SqlServerUtil::sqlsrvCreate($this->SqlServer ,'gz_Yfucaicbfjijia_ZLCCG' , $jjgcjTemp);
    						}
    						//装试车间(辅材)	
    						$zscjTemp = $this->getjixingQR($v['fmodel'],'28007',$v['fbillno']);
    						if(empty($zscjTemp)){
    							showMsg(400,  '装试车间(辅材) ,机型'.$v['fmodel'].'数据为空 '.$checkStr.'，请检查');
    						}
    						if($zscjTemp){
    							SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_Yfucaicbfzshi_ZLCCG' , ['fjybjbillno'=> "'".$v['fbillno']."'" ],true);
    							SqlServerUtil::sqlsrvCreate($this->SqlServer ,'gz_Yfucaicbfzshi_ZLCCG' , $zscjTemp);
    						}
    						//售后成本	 26012
    						$shcbTemp = $this->getjixingQR($v['fmodel'],'26012',$v['fbillno']);
    						if(empty($shcbTemp)){
    							showMsg(400,  '售后成本 ,机型'.$v['fmodel'].'数据为空 '.$checkStr.'，请检查');
    						}
    						if($shcbTemp){
    							SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_Yshtswhcb_ZLCCG' , ['fjybjbillno'=> "'".$v['fbillno']."'" ],true);
    							SqlServerUtil::sqlsrvCreate($this->SqlServer ,'gz_Yshtswhcb_ZLCCG' , $shcbTemp);
    						}
    						//运保费
    						$ybTemp = $this->getjixingQR($v['fmodel'],'26016',$v['fbillno']);
    						if(empty($ybTemp)){
    							showMsg(400, '运保费 ,机型'.$v['fmodel'].'数据为空 '.$checkStr.'，请检查');
    						}
    						if($ybTemp){
    							SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_Yyunbaof_ZLCCG' , ['fjybjbillno'=> "'".$v['fbillno']."'" ],true);
    							SqlServerUtil::sqlsrvCreate($this->SqlServer ,'gz_Yyunbaof_ZLCCG' , $ybTemp);
    						}
    						//水电
    						$sdTemp = $this->getjixingQR($v['fmodel'],'26011',$v['fbillno']);
    						if(empty($sdTemp)){
    							showMsg(400,'水电费 ,机型'.$v['fmodel'].'数据为空 '.$checkStr.'，请检查');
    						}
    						if($sdTemp){
    							SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_Yshuidianf_ZLCCG' , ['fjybjbillno'=> "'".$v['fbillno']."'" ],true);
    							SqlServerUtil::sqlsrvCreate($this->SqlServer ,'gz_Yshuidianf_ZLCCG' , $sdTemp);
    						}
    						//图纸送审CCS	,   图纸送审ABS	,图纸送审LR,	图纸送审DNV-GL	 ,   图纸送审BV,	图纸送审NK
//     						$tuzhissTemp =[
//     								'fjybjbillno' => $v['fbillno'] ,
//     								'fbrand'=>$v['fbrand'],
//     								'fmodel'=>$v['fmodel'],
//     								'CCS'=>$v['ftuzhissCCS'],
//     								'ABS'=>$v['ftuzhissABS'],
//     								'LR'=>$v['ftuzhissLR'],
//     								'DNVGL'=>$v['ftuzhissDNVGL'],
//     								'BV'=>$v['ftuzhissBV'],
//     								'NK'=>$v['ftuzhissNK'],
//     								'fallamount'=>$v['fallamount'],
    								
//     						];
							//生产部机型
    						$prodTemp = $this->getProdQR($v['fmodel'],'14010',$v['fbillno'] ,$csSetData ); 
    						if(empty($prodTemp)){
    							showMsg(400, '生产部机型 ,机型'.$v['fmodel'].'数据为空 '.$checkStr.'，请检查');
    						}
    						if($prodTemp){
    							SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_YBaseProduce_ZLCCG' , ['fjybjbillno'=> "'".$v['fbillno']."'" ],true);
    							SqlServerUtil::sqlsrvCreate($this->SqlServer ,'gz_YBaseProduce_ZLCCG' , $prodTemp);
    						}
    					}
    					//折旧
    					//财务
    					$sql="update {$db} set  fisqr = 3, fcaiwuRemark = '{$cwname}',fcreatetimecw ='{$time}',opernameCW ='{$opername}'  where 1=1 {$FIDStr}   ";
    				
//     					echo $sql;die;
    				}
    			}else{
    				if($FRepKey == '30005'){
    					foreach ($data as $k=>$v)
    					{
    						if($v['fisqr']> 1){
    							showMsg(400,'不能反确认，等待采购、财务反确认。');
    						}
    					}
    					//技术部
    					$sql="update {$db} set  fisqr = 0 ,fjishuRemark ='',opernameJS ='{$opername}'  where 1=1 {$FIDStr}   ";
    				}
    				
    				if($FRepKey == '30006'){
    					foreach ($data as $k=>$v)
    					{
    						if($v['fisqr']> 2){
    							showMsg(400,'不能反确认，等待财务反确认。');
    						}
    					}
    					//采购部
    					$sql="update {$db} set  fisqr = 0, fcaigouRemark = '' ,opernameCG ='{$opername}' where 1=1 {$FIDStr}   ";
    				}
    				
    				
    				if($FRepKey == '30007'){
    					// 判断其他部门 是否 已确认 ==反确认
    					foreach ($data as $k=>$v)
    					{
    						 
	    					$resJYQR  = SqlServerUtil::execToSql($this->SqlServer, "select fbillno,fstatus from gz_YbaojiadanZLC where fbillno ='{$v['fbillno']}'  ",2 );
	    					if($resJYQR){
	    						//判断是否有值
	    						if($resJYQR['fstatus']>0){
	    							showMsg(400,$v['fbillno'].'经营报价已审核，无法反确认');
	    						}
	    						showMsg(400,$v['fbillno'].'经营报价已生成，请删除再反确认');
	    					}
    					}
    					//财务
    					$sql="update {$db} set  fisqr = 1,fcaigouRemark = '' ,fjishuRemark ='',fcaiwuRemark ='',fcreatetimecg=NULL,fcreatetimejs=NULL, fcreatetimecw=NULL,opernameCW ='{$opername}'  where 1=1 {$FIDStr}   ";
    					
    				}
    				
    			}
    		}
	    	
	    	// 启动事务
	    	if (sqlsrv_begin_transaction($this->SqlServer) === false) {
	    		die(print_r(sqlsrv_errors(), true));
	    	}
// 	    	echo $sql;die;
	    	$sqlStr = iconv( 'UTF-8','GBK',$sql);
	    	$up = sqlsrv_query($this->SqlServer, $sqlStr);
	    	if($up  ){
	    		sqlsrv_commit($this->SqlServer);
	    		showMsg(0,'成功');
	    	}else {
	    		sqlsrv_rollback($this->SqlServer);
	    		showMsg(1,'失败');
	    	}
	    	
	    	showMsg(0);
    	}else{
    		showMsg(400,'请选中一行数据');
    	}
    	
    }
    	
    
    /**
    * 走流程 -- 机型 新增
    * @date: 2023年2月17日 下午4:33:23
    * @author: juyi
    */
    public function zlcJXQRAdd(Request $request){
    	$FRepKey = $request->get('FRepKey');
    	$opername = $request->get('opername');
    	
    	$getMkName =  '已确认' ;
    	$db = columnBiao('30005');
    	
    	$jsname ='技术'.$getMkName ;
    	$cgname ='采购'.$getMkName ;
    	$cwname ='财务'.$getMkName ;
    	$data = $request ->get('data')  ;
    	//输入机型内容
    	$fjixingnr = $request ->get('fjixingnr')  ;
    	/* 30005	经营报价机型(技术)
    	30006	经营报价机型(采购)
    	30007	经营报价机型(财务)
    	30008	经营报价机型(业务) */
    	$result =[];
    	if($data){
    		foreach ($data as $k =>$v )
    		{
    			$result[$k]['fmodel'] = $v['fmodel'] ; 
    			$result[$k]['fbrand'] =  strtoupper(str_replace(' ','',$v['fbrand'])); 
    			$result[$k]['fpower'] = $v['fpower'] ; 
    			if($FRepKey == '30008'){
    				$result[$k]['fbillno'] = $this->getDanHao($FRepKey) ;
    			}
    			
    			$result[$k]['fjixingnr'] = $fjixingnr ;
    			$result[$k]['fcreatemanager'] = $opername;
    		}
    		SqlServerUtil::sqlsrvAllTosql($this->SqlServer ,$db , $result);
    	}
    	
    	
    	showMsg(0);
    	
    	
    	
    }
    
    public function getJzData($fmodel){
    	
    	$sql =" select u1.*,v1.fprodno from gz_Yjiazhangcbf v1 inner join gz_YjiazhangcbfSet u1 on v1.fcode = u1.fcode where v1.fprodno ='{$fmodel}'";
    	$data = SqlServerUtil::execTosqlOK($this->SqlServer,$sql);
    	$result=[];
    	if($data){
    		$result = arraykeyToLower($data);
    	}
    	return $result ; 
    }
    
    /**
    * 业务需求 --
    * @date: 2023年3月3日 下午9:06:35
    * @author: juyi
    * @param: variable
    * @return:
    */
    public function getJzBJData($fmodel,$fbillno , $FRepKey){  
    	$sql ='';
    	if(in_array($FRepKey ,['14009' , '14011' ,'14012','14013'])){
    		$sql =" select u1.*,v1.fprodno,v1.fbillno from gz_Yjiazhangcbf v1 inner join gz_YjiazhangcbfSet u1 on v1.fcode = u1.fcode where v1.fbillno ='{$fbillno}' and v1.fprodno ='{$fmodel}'";
    	}elseif(in_array($FRepKey ,[ '34001'] )){
    		$sql =" select u1.*,v1.fprodno,v1.fbillno from gz_Yjiazhangcbf_HXJZ v1 inner join gz_YjiazhangcbfSet u1 on v1.fcode = u1.fcode where v1.fbillnoentry ='{$fbillno}' and v1.fprodno ='{$fmodel}'";
    	}
    	$data = SqlServerUtil::execTosqlOK($this->SqlServer,$sql);
    	$result=[];
    	if($data){
    		$result = arraykeyToLower($data);
    	}
    	return $result ;
    }
    
    
    /**
    * 经营报价 点击明细 
    * @date: 2023年2月27日 下午9:00:27
    * @author: juyi
    */
    public function getZLCMX(Request $request){
    	$FRepKey = $request->get('FRepKey');
    	$opername = $request->get('opername');
    	$fbrand = $request->get('fbrand');
    	$fmodel = $request->get('fmodel');
    	//经营报价
    	$fjybjbillno = $request->get('fjybjbillno');
    	
    	$db = columnBiao($FRepKey) ; 
    	$db = $db.'_ZLCCG';
    	if(in_array($FRepKey, ['26009','26022' ])){
    		$cgsql = "set nocount on
				if object_id('tempdb..#tmpprodnoCGZLC') is not null drop table #tmpprodnoCGZLC
				create table #tmpprodnoCGZLC(
				fid int identity(1,1),
				fprodno varchar(200),
				fjybjbillno varchar(100)
				)
				insert into #tmpprodnoCGZLC(fprodno,fjybjbillno)
				select fprodno,max(fjybjbillno) fjybjbillno from gz_Ycaigoucbf_ZLCCG u1 where 1=1 and u1.fbrand='{$fbrand}' and u1.fprodno='{$fmodel}' group by fprodno
				declare @sqlmax varchar(max),@filvalue varchar(200)
				declare @i int ,@rwcount int
				set @i=1
				select @rwcount=count(1) from #tmpprodnoCGZLC
				set @sqlmax='select u1.fcode as ''代码'',min(v1.fname) as ''名称'''
				while @i<=@rwcount
				begin
				select @filvalue=fprodno from #tmpprodnoCGZLC where fid=@i
				set @sqlmax=@sqlmax+',sum(case when u1.fprodno='''+@filvalue+''' then isnull(fallAmount,0) else 0 end) as ['+ @filvalue +']'
				set @i=@i+1
				end
				set @sqlmax=@sqlmax+ ' from gz_Ycaigoucbf_ZLCCG  u1 
				inner join gz_YcaigoucbfSet v1 on u1.fcode=v1.fcode and u1.fbrand=v1.fbrand 
				where 2=2 and u1.fbrand=''{$fbrand}'' and u1.fprodno=''{$fmodel}''  and u1.fjybjbillno = ''{$fjybjbillno}''  group by u1.fcode '
				exec( @sqlmax) " ;
//     		echo $cgsql;die;
    		$data = SqlServerUtil::execTosqlYes($this->SqlServer, $cgsql );
    		if($data){
    			foreach ($data as $k => &$v)
    			{
    				foreach ($v as $k1=>$v1)
    				{
    					if( $v[$k1] ==='.00' || $v[$k1] ==='.000' || $v[$k1] ==='.0000' || ($v[$k1]>0 && $v[$k1]<1) ){
    						$v[$k1] = floatval($v1);
    					}
    				}
    			}
    		}
    		showMsg(0,'成功' ,$data );
    		
    	}
		//人工费用    	
    	if(in_array($FRepKey, [ '26001' ])){
    		$sql =" SELECT
    		row_number () OVER ( ORDER BY v1.fid DESC ) AS rownumber,
    		v1.fid AS fidprod,
    		v1.fmodel ,
    		v1.fbrand ,
    		v1.fhanjiegs as fhanjiecj ,
    		v1.fjijiags as fjijiacj ,
    		v1.fzhuangshigs as fzhuangshicj ,
    		(v1.fhanjiegs + v1.fjijiags +v1.fzhuangshigs) as fgongshi,
    		v1.fhanjiePrice as fhanjiePrice,
    		v1.fjijiaPrice as fjijiaPrice ,
    		v1.fzhuangshiPrice as fzhuangshiprice,
    		round(v1.fhanjiegs*v1.fhanjiePrice +v1.fjijiags*v1.fjijiaPrice +v1.fzhuangshigs*v1.fzhuangshiPrice , 2)   as fallAmount,
    		round((v1.fhanjiegs*v1.fhanjiePrice +v1.fjijiags*v1.fjijiaPrice +v1.fzhuangshigs*v1.fzhuangshiPrice)*1.13 , 2)   as ffaxallAmount,
    		u1.fid , u1.fcreatetime ,u1.FStatus ,u1.checkName
    		FROM  gz_YBaseJS_ZLCCG v1
    		LEFT JOIN gz_Yrengongf u1 ON v1.fmodel = u1.fmodel   where v1.fjybjbillno = '{$fjybjbillno}' " ;
    		$data = SqlServerUtil::execTosqlOK($this->SqlServer,$sql);
    		$result=[];
    		if($data){
    			$result = arraykeyToLower($data);
    		}
    		showMsg(0,'成功',$result) ;
    	}
    	
    	$sql =" select * from {$db}  where 1=1 and fjybjbillno = '{$fjybjbillno}' " ;
//     	echo $sql;die;  
    	$data = SqlServerUtil::execTosqlOK($this->SqlServer,$sql);
    	$result=[];
    	if($data){
    		$result = arraykeyToLower($data);
    	}
    	showMsg(0,'成功',$result) ; 
    }
    
    /**
    * 正式报价单 -- 点击 明细
    * @date: 2023年2月28日 上午10:40:29
    * @author: juyi
    * fjzdetail -- 加账明细
    */
    public function getBAOJIAMX(Request $request){
    	$FRepKey = $request->get('FRepKey');
    	$opername = $request->get('opername');
    	$fbrand = $request->get('fbrand');
    	$fmodel = $request->get('fmodel');
    	//经营报价
    	$fjybjbillno = $request->get('fjybjbillno');
    	$fjzdetail = $request->get('fjzdetail')??0;
    	
    	$fzlf = $request->get('fzlf')??0;
    	
    	
    	$db = columnBiao($FRepKey) ;
    	$db = $db.'_BAOJIA';
    	if(in_array($FRepKey, ['26009','26022' ])){
    		$cgsql = "set nocount on
    		if object_id('tempdb..#tmpprodnoCGBJ') is not null drop table #tmpprodnoCGBJ
    		create table #tmpprodnoCGBJ(
    		fid int identity(1,1),
    		fprodno varchar(200),
    		fjybjbillno varchar(100)
    		)
    		insert into #tmpprodnoCGBJ(fprodno,fjybjbillno)
    		select fprodno,max(fjybjbillno) fjybjbillno from gz_Ycaigoucbf_BAOJIA u1 where 1=1 and u1.fbrand='{$fbrand}' and u1.fprodno='{$fmodel}' group by fprodno
    		declare @sqlmax varchar(max),@filvalue varchar(200)
    		declare @i int ,@rwcount int
    		set @i=1
    		select @rwcount=count(1) from #tmpprodnoCGBJ
    		set @sqlmax='select u1.fcode as ''代码'',min(v1.fname) as ''名称'''
    		while @i<=@rwcount
    		begin
    		select @filvalue=fprodno from #tmpprodnoCGBJ where fid=@i
    		set @sqlmax=@sqlmax+',sum(case when u1.fprodno='''+@filvalue+''' then isnull(fallAmount,0) else 0 end) as ['+ @filvalue +']'
    		set @i=@i+1
    		end
    		set @sqlmax=@sqlmax+ ' from gz_Ycaigoucbf_BAOJIA  u1
    		inner join gz_YcaigoucbfSet v1 on u1.fcode=v1.fcode and u1.fbrand=v1.fbrand
    		where 2=2 and u1.fbrand=''{$fbrand}'' and u1.fprodno=''{$fmodel}''  and u1.fjybjbillno = ''{$fjybjbillno}''  group by u1.fcode '
    		exec( @sqlmax) " ;
//     		echo $cgsql;die;
    		$data = SqlServerUtil::execTosqlYes($this->SqlServer, $cgsql );
    		if($data){
    			foreach ($data as $k => &$v)
    			{
    				foreach ($v as $k1=>$v1)
    				{
    					if( $v[$k1] ==='.00' || $v[$k1] ==='.000' || $v[$k1] ==='.0000' || ($v[$k1]>0 && $v[$k1]<1) ){
    						$v[$k1] = floatval($v1);
    					}
    				}
    			}
    		}
    		showMsg(0,'成功' ,$data );
    		
    	}
    	//加账   加账清单(采购)   26005
    	if(in_array($FRepKey, ['26005','26023','26025','14009' ,'14011','14012','14013'])){
    		//  $fjzdetail   == 1 
    		if( $fjzdetail  == 1) {
    			$bumenStr = "";
    			if($FRepKey  == '26005'){
    				//采购部
    				$bumenName ="采购";
    				$bumenStr=" and ( charindex('{$bumenName}',v1.fdanweibumen)>0   )" ;
    				$baseSql =" select v1.fbrand as '品牌',v1.fcode as '代码',v1.fprodno as '机型',v1.fname as '名称',v1.fywqty as '数量',v1.foriamount as  N'单价'   from gz_Yjiazhangcbf_BAOJIA v1  where 1=1 and v1.fjybjbillno = '{$fjybjbillno}'  {$bumenStr} " ;
    				      			
    			}elseif($FRepKey == '26023'){
    				//技术中心
    				$bumenName ="技术";
    				$bumenStr=" and ( charindex(N'{$bumenName}',v1.fdanweibumen)>0   )" ;
    				//,v1.fallamount as  N'金额'
    				$baseSql =" select v1.fbrand as  N'品牌',v1.fcode as  N'代码',v1.fprodno as  N'机型',v1.fname as  N'名称',v1.fywqty as  N'数量',v1.foriamount as  N'单价',v1.fsxQty as  N'生效台数'   from gz_Yjiazhangcbf_BAOJIA v1  where 1=1 and v1.fjybjbillno = '{$fjybjbillno}'  {$bumenStr} " ;
    			 	
    			}elseif($FRepKey  == '26025'){
    				//其他部门    =  售后服务部、生产管理部  ， 质量管理部
    				$bumenName ="售后";
    				$bumenName1 ="生产";
    				$bumenName2 ="质量";
    				$bumenName3 ="其他";
    				$bumenStr=" and ( charindex('{$bumenName}',v1.fdanweibumen)>0  or charindex('{$bumenName1}',v1.fdanweibumen)>0 or charindex('{$bumenName2}',v1.fdanweibumen)>0 or charindex('{$bumenName3}',v1.fdanweibumen)>0  )" ;
    				$baseSql =" select select v1.fbrand as  N'品牌',v1.fcode as  N'代码',v1.fprodno as  N'机型',v1.fname as  N'名称',v1.fywqty as  N'数量',v1.foriamount as  N'单价',v1.fsxQty as  N'生效台数'   from gz_Yjiazhangcbf_BAOJIA v1  where 1=1 and v1.fjybjbillno = '{$fjybjbillno}'  {$bumenStr} " ;
    			}elseif($FRepKey  == '14009'){
    				$fkeywordStr  = "" ;
    				if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
    					$keyword = $request->keyword  ;
    					$fkeywordStr=" and ( charindex('{$keyword}',u1.fname)>0 or charindex('{$keyword}',u1.fcode)>0   )" ;
    				}
    				//业务需求 加账
    				$baseSql ="  select  	row_number() OVER(ORDER BY v1.fcode  )   as N'序号',  u1.fbrand as N'品牌',v1.fcode as N'代码',v1.fprodno as N'机型',u1.fname as N'名称',v1.fywqty as N'数量' ,u1.fzjQty as N'单位'
    				,v1.fnote as '备注' from gz_Yjiazhangcbf v1  left join gz_YjiazhangcbfSet u1 on u1.fcode =  v1.fcode
    				where 1=1 and v1.fbillno = '{$fjybjbillno}' {$fkeywordStr} ";
    				
    			}elseif($FRepKey  == '14011'){
    				//技术 14011
    				$baseSql ="  select  u1.fbrand as N'品牌',v1.fcode as N'代码',v1.fprodno as N'机型',
					u1.fname as N'名称',u1.fzjQty as N'单位',v1.fywqty as N'数量' ,t1.fallAmount as N'金额'
    				from gz_Yjiazhangcbf v1  left join gz_YjiazhangcbfSet u1 on u1.fcode =  v1.fcode
					left join gz_YjiazhangcbfMX  t1 on t1.fcode = v1.fcode  and t1.fprodno = v1.fprodno 
    				where 1=1 and v1.fbillno = '{$fjybjbillno}' and  ( charindex('技术',u1.fdanweibumen)>0 ) ";
    				
    			}elseif($FRepKey  == '14012'){
    				//采购 14012
    				$baseSql ="  select  u1.fbrand as N'品牌',v1.fcode as N'代码',v1.fprodno as N'机型',
					u1.fname as N'名称',u1.fzjQty as N'单位',v1.fywqty as N'数量'  ,t1.fallAmount as N'金额'
    				from gz_Yjiazhangcbf v1  left join gz_YjiazhangcbfSet u1 on u1.fcode =  v1.fcode
					left join gz_YjiazhangcbfMX  t1 on t1.fcode = v1.fcode  and t1.fprodno = v1.fprodno 
    				where 1=1 and v1.fbillno = '{$fjybjbillno}' and  ( charindex('采购',u1.fdanweibumen)>0 ) ";
    				
    			}elseif($FRepKey  == '14013'){
    				//财务 14013
    				$baseSql ="  select  u1.fbrand as N'品牌',v1.fcode as N'代码',v1.fprodno as N'机型',
    				u1.fname as N'名称',u1.fzjQty as N'单位',v1.fywqty as N'数量'  ,t1.fallAmount as N'金额'
    				from gz_Yjiazhangcbf v1  left join gz_YjiazhangcbfSet u1 on u1.fcode =  v1.fcode
    				left join gz_YjiazhangcbfMX  t1 on t1.fcode = v1.fcode  and t1.fprodno = v1.fprodno
    				where 1=1 and v1.fbillno = '{$fjybjbillno}' and  ( charindex('其他',fdanweibumen)>0  or charindex('生产',fdanweibumen)>0  or charindex('质量',fdanweibumen)>0  or charindex('售后',fdanweibumen)>0  ) ";
    				
    			}else{
    				//查询市场部需求明细
    				$baseSql =" select u1.fbrand as  N'品牌',v1.fcode as  N'代码',v1.fprodno as  N'机型',u1.fname as  N'名称',v1.fywqty as  N'数量'
    						from gz_Yjiazhangcbf v1   inner join gz_Yjiazhangcbfset u1  on v1.fcode = u1.fcode
    						where 1=1 and v1.fbillno = '{$fjybjbillno}'  " ;
    				//$baseSql =" select v1.fbrand as  N'品牌',v1.fcode as  N'代码',v1.fprodno as  N'机型',v1.fname as  N'名称',v1.fywqty as  N'数量'    from gz_Yjiazhangcbf_BAOJIA v1  where 1=1 and v1.fjybjbillno = '{$fjybjbillno}'  " ;
    			}
    			//v1.fid,v1.fbrand,v1.fcode,v1.fprodno,v1.fqty ,v1.fname,v1.fdanweibumen,v1.fywqty,v1.foriamount,v1.fyzamount
    			//$baseSql =" select v1.*  from gz_Yjiazhangcbf_BAOJIA v1  where 1=1 and v1.fjybjbillno = '{$fjybjbillno}'  {$bumenStr} " ;
    		  
    			$res = SqlServerUtil::execTosqlOKTO($this->SqlServer,  $baseSql);
//     			dd($res);
    			$result =[];
    			if($res){
    				$result = arraykeyToLower($res);
    				foreach ($result as $k1=>&$v1)
    				{
    					foreach ($v1 as $k2=>$v2)
    					{
    						if( $v1[$k2] ==='.00' || $v1[$k2]  ==='.0000'  || $v1[$k2]  ==='.000' || $v1[$k2]  ==='.000000' || ($v1[$k2]>0 && $v1[$k2]<1) ){
    							$v1[$k2] = floatval($v2);
    						}
    						// fnbfhyx
    					}
    				}
    			}
    			showMsg(0,'成功' , $result) ;
    		
    		}else{
    		
		    		$bumenStr = "";
		    		if($request ->fdanweibumen ==1  ){
		    			//加账采购
		    			$bumenStr = " and u1.fbm =''CG'' " ; 
		    		}elseif($request ->fdanweibumen ==2){
		    			//技术
		    			$bumenStr = " and u1.fbm =''JS'' " ; 
		    		}elseif($request ->fdanweibumen ==3){
		    			//其他
		    			$bumenStr = " and u1.fbm =''QT'' " ; 
		    		}
		    		$sqljz =" set nocount on
		    		if object_id('tempdb..#tmpprodnoJZ') is not null drop table #tmpprodnoJZ
		    		create table #tmpprodnoJZ(
		    		fid int identity(1,1),
		    		fprodno varchar(200),
		    		fjybjbillno varchar(100)
		    		)
		    		insert into #tmpprodnoJZ(fprodno,fjybjbillno)
		    		select fprodno,max(fjybjbillno) fjybjbillno from gz_Yjiazhangcbf_BAOJIA u1 
					where 1=1 and u1.fbrand='{$fbrand}' and u1.fprodno='{$fmodel}' and  fjybjbillno = '{$fjybjbillno}' group by fprodno,fjybjbillno
		    		declare @sqlmax varchar(max),@filvalue varchar(200)
		    		declare @i int ,@rwcount int
		    		set @i=1
		    		select @rwcount=count(1) from #tmpprodnoJZ
		    		set @sqlmax='select u1.fcode as ''代码'',min(u1.fname) as ''名称'''
		    		while @i<=@rwcount
		    		begin
		    		select @filvalue=fprodno from #tmpprodnoJZ where fid=@i
		    		set @sqlmax=@sqlmax+',sum(case when u1.fprodno='''+@filvalue+''' then isnull(u1.fallAmount,0) else 0 end) as ['+ @filvalue +']'
		    		set @i=@i+1
		    		end
		    		set @sqlmax=@sqlmax+ ' from gz_Yjiazhangcbf_BAOJIA  u1
		    		where 2=2 and u1.fbrand=''{$fbrand}'' and u1.fprodno=''{$fmodel}''  and u1.fjybjbillno = ''{$fjybjbillno}''  {$bumenStr} group by u1.fcode '
		    		exec( @sqlmax) " ;
// 		    		echo  $sqljz; die;
		    		$data = SqlServerUtil::execTosqlYes($this->SqlServer, $sqljz );
		    		
		    		if($data){
		    			foreach ($data as $k => &$v)
		    			{
		    				foreach ($v as $k1=>$v1)
		    				{
		    					if( $v[$k1] ==='.00' || $v[$k1] ==='.000' || $v[$k1] ==='.0000' || ($v[$k1]>0 && $v[$k1]<1) ){
		    						$v[$k1] = floatval($v1);
		    					}
		    				}
		    			}
		    		}
		    		showMsg(0,'成功' ,$data );
    		}
    	}
    	//后续 合同专利费  
    	if($fzlf == 1 && in_array($FRepKey, [ '26004' ]) ){
    		$fbillnoentry = $request->fbillnoentry;
    		$sql =" select fname as '名称' ,fprodno as '品牌',fPatentfee as '收费专利',FExchangeRate as '汇率' ,
			fsetzhaunlifeibl as '专利费比例' 
			 from gz_Yzhuanlif_QDHT  where 1=1 and fjybjbillno = '{$fjybjbillno}' and fbillnoentry ='{$fbillnoentry}' " ;
//     		echo $sql;die;
    		$data = SqlServerUtil::execTosqlOKTO($this->SqlServer,$sql);
    		$result=[];
    		if($data){
    			$result = arraykeyToLower($data);
    		}
    		showMsg(0,'成功',$result) ; 
    		
    	}
    	
    	//直接人工费
    	if(in_array($FRepKey, [ '26001' ])){
    		$sql =" SELECT
				row_number ( ) OVER ( ORDER BY v1.fid DESC ) AS rownumber,
				v1.fid AS fidprod,
				v1.fmodel ,
				v1.fbrand ,
			v1.fhanjiegs as fhanjiecj ,
			v1.fjijiags as fjijiacj ,
			v1.fzhuangshigs as fzhuangshicj ,
			 (v1.fhanjiegs + v1.fjijiags +v1.fzhuangshigs) as fgongshi,
			v1.fhanjiePrice as fhanjiePrice,
			 v1.fjijiaPrice as fjijiaPrice ,
			 v1.fzhuangshiPrice as fzhuangshiprice,
			 round(v1.fhanjiegs*v1.fhanjiePrice +v1.fjijiags*v1.fjijiaPrice +v1.fzhuangshigs*v1.fzhuangshiPrice , 2)   as fallAmount,
			 round((v1.fhanjiegs*v1.fhanjiePrice +v1.fjijiags*v1.fjijiaPrice +v1.fzhuangshigs*v1.fzhuangshiPrice)*1.13 , 2)   as ffaxallAmount,
			u1.fid , u1.fcreatetime ,u1.FStatus ,u1.checkName 
			FROM  gz_YBaseJS_BAOJIA v1
			LEFT JOIN gz_Yrengongf u1 ON v1.fmodel = u1.fmodel   where v1.fjybjbillno = '{$fjybjbillno}' " ;
    		$data = SqlServerUtil::execTosqlOK($this->SqlServer,$sql);
    		$result=[];
    		if($data){
    			$result = arraykeyToLower($data);
    		}
    		showMsg(0,'成功',$result) ; 
    		
    	}
    	
    	if(  in_array($FRepKey, [ '26003' ]) ){
    	 
    		$sql =" select  fjybjbillno as '单号', fbrand as '品牌',fprodno as '机型',fprice as '柴油单价(元/kg)',FdieselOilQty as '燃油量-柴油(kg)' ,
    		fCylinderoil as '气缸油(kg)',fCylinderoilPrice as '气缸油单价(元/kg)',fgasQty as '燃气量(kg)',fgasPrice as '燃气单价(元/kg)',
			fsxQty as '生效台数' ,fnoranyou	as '非首台燃油' , fnoranqi as '非首台燃气' ,	fnoqigang as '非首台气缸' ,
			fAllamount as '合计金额' 
    		from gz_Yyouqif_BAOJIA  where 1=1 and fjybjbillno = '{$fjybjbillno}'    " ;
    		//     		echo $sql;die;
    		$data = SqlServerUtil::execTosqlOKTO($this->SqlServer,$sql);
    		$result=[];
    		if($data){
    			$result = arraykeyToLower($data);
    		}
    		showMsg(0,'成功',$result) ;
    		
    	}
    	//委外 费用
    	if(in_array($FRepKey, [ '26014' ])){
    		$sql ="select row_number() over(order by v1.fid desc ) as rownumber  ,v1.fid as fidprod ,v1.fbrand 
			 ,v1.fmodel ,v1.funit ,v1.fpower ,v1.fmoli as fmali ,v1.fzhuansu  ,v1.fjuanyuan ,v1.flingxingjg ,v1.fsuanxilh as fsuanxi ,v1.fjizuo ,v1.fjijia  ,v1.fqita ,v1.fpaiyanguanzq as fpaiyanguan ,v1.fzoutai ,
			v1.fgongzhuangjt as fgzfentan ,
			v1.fbgrpaiyanguan as fpaiyanguanBGR ,
			v1.fbgrjinqi AS fjinqixiang,
			v1.fbgrzhengji AS fzjguan ,
			(v1.fjuanyuan +v1.flingxingjg +v1.fsuanxilh +
				v1.fjizuo +v1.fjijia + v1.fqita +v1.fpaiyanguanzq +	v1.fzoutai+v1.fgongzhuangjt +v1.fbgrpaiyanguan +v1.fbgrjinqi +v1.fbgrzhengji  ) as  fallAmount,
			u1.fid ,u1.fcreatetime ,u1.FStatus ,u1.checkName
			 from gz_YBaseProduce_BAOJIA  v1 
			left join  gz_Yweiwaif u1  on v1.fmodel = u1.fmodel
			  where 1=1 and   v1.fjybjbillno = '{$fjybjbillno}' " ;
//     		echo $sql;die;
    		$data = SqlServerUtil::execTosqlOK($this->SqlServer,$sql);
    		$result=[];
    		if($data){
    			$result = arraykeyToLower($data);
    			foreach ($result as $k1=>&$v1)
    			{
    				foreach ($v1 as $k2=>$v2)
    				{
    					if( $v1[$k2] ==='.00' || $v1[$k2]  ==='.0000'  || $v1[$k2]  ==='.000' || $v1[$k2]  ==='.000000' || ($v1[$k2]>0 && $v1[$k2]<1) ){
    						$v1[$k2] = floatval($v2);
    					}
    					// fnbfhyx
    				}
    			}
    		}
    		showMsg(0,'成功',$result) ; 
    	}
    	
    	//图纸送审费  26020 
    	if(in_array($FRepKey, [ '26020' ])){
    		$sql ="select row_number() over(order by v1.fid desc ) as rownumber,v1.*
			,v1.fid as fidjs  
			 from gz_YBaseJS_BAOJIA    v1  
			 left join gz_Ytzsongshenf tzss on tzss.fmodel = v1.fmodel
			 where 1=1  and  v1.fjybjbillno = '{$fjybjbillno}' " ;
    		//     		echo $sql;die;
    		$data = SqlServerUtil::execTosqlOK($this->SqlServer,$sql);
    		$result=[];
    		if($data){
    			$result = arraykeyToLower($data);
    		}
    		showMsg(0,'成功',$result) ;
    	}
    	
    	//特定刀具
    	if(in_array($FRepKey, [ '26018' ])){
    		$sql ="SELECT
			row_number ( ) OVER ( ORDER BY v1.fid DESC ) AS rownumber,
			v1.fid AS fidprod,
			v1.fmodel ,
			v1.fbrand ,
		v1.fxjxtsdaoju as fxjxtsdaoju,
		v1.fdaojuxiaohao as fdjuxiaohao,
		v1.fxjxtsdaoju*10000/5  as  fallAmount,
		u1.fid ,5 as ffentantaishu,
			u1.fcreatetime ,
			u1.FStatus ,
			u1.checkName 
		FROM
		gz_YBaseProduce_BAOJIA v1
		LEFT JOIN gz_Ytddaojuf u1 ON v1.fmodel = u1.fmodel   
		where 1=1 and  v1.fjybjbillno = '{$fjybjbillno}' " ;
    		//     		echo $sql;die;
    		$data = SqlServerUtil::execTosqlOK($this->SqlServer,$sql);
    		$result=[];
    		if($data){
    			$result = arraykeyToLower($data);
    		}
    		showMsg(0,'成功',$result) ;
    	}
    	//特定工装
    	if(in_array($FRepKey, [ '26017' ])){
    		$sql ="SELECT
    		row_number ( ) OVER ( ORDER BY v1.fid DESC ) AS rownumber,
    		v1.fid AS fidprod,
    		v1.fmodel ,
    		v1.fbrand ,
    		v1.fhanjiegz,
    		v1.fjijiagz ,
    		v1.fzhuangshigz,
    		v1.fshichegz,
    		v1.fbgrzhengji as fzjguan,
    		v1.ffayungzzj,
    		v1.ffayungzfd,
    		10 as ffentantaishu,
    		(round((v1.fhanjiegz +v1.fjijiagz +v1.fzhuangshigz +v1.fshichegz)/10 ,2) +v1.ffayungzzj)  as fztfyAmount,
    		(round((v1.fhanjiegz +v1.fjijiagz +v1.fzhuangshigz +v1.fshichegz)/10 ,2) +v1.ffayungzfd) as fftfyAmount,
    		u1.fid , u1.fcreatetime ,u1.FStatus ,u1.checkName
    		FROM
    		gz_YBaseProduce_BAOJIA v1
    		LEFT JOIN gz_Ytdgongzhuangf u1 ON v1.fmodel = u1.fmodel   where 1=1 and  v1.fjybjbillno = '{$fjybjbillno}' " ;
    		$data = SqlServerUtil::execTosqlOK($this->SqlServer,$sql);
    		$result=[];
    		if($data){
    			$result = arraykeyToLower($data);
    		}
    		showMsg(0,'成功',$result) ;
    	}
    	// ICER数据库信息 
    	if(in_array($FRepKey, [ '27010','27011' ])){
    		$sql =" select * from gz_YjzICERDB_BAOJIA where 1=1 and fmodel = '{$fmodel}' " ;
    		$data = SqlServerUtil::execTosqlOK($this->SqlServer,$sql);
    		$result=[];
    		if($data){
    			$result = arraykeyToLower($data);
    		}
    		showMsg(0,'成功',$result) ; 
    	}
    	
    	//IECR增加生产成本 27006 == 燃气  fICERAmount    ,,   27015 ==  燃油
    	if(in_array($FRepKey, [ '27006','27015' ])){
    		// 27015  v1.fisryrq = '燃油'    gz_YjzICERRanYouHZ
    		// 27006  v1.fisryrq = '燃气'    gz_YjzICERQT
    		$rows = $request->row ;
    		$fjybjbillno =   $rows['fbillno'] ;
    		$fmodel =   $rows['fmodel'] ;
    		$fisryrq =   $rows['fisryrq'] ;
    		$db ='gz_YjzICERQT';
    		if($fisryrq == '燃油'){
    			$db = 'gz_YjzICERRanYouHZ' ;
    		}
    		$sql =" select * from {$db}  where 1=1 and fbillno = '{$fjybjbillno}' " ;
    		$result=[];
    		$data = SqlServerUtil::execTosqlOK($this->SqlServer,$sql);
    		if($data){
    			$result = arraykeyToLower($data);
    		}
    		showMsg(0,'成功',$result) ; 
    	}
    	//SCR增加的生产成本 27001	fSCRAmount
    	if(in_array($FRepKey, [ '27001' ])){
    		$rows = $request->row ;
    		$fjybjbillno =   $rows['fbillno'] ;
    		$fmodel =   $rows['fmodel'] ;
    		$fisscr =   $rows['fisscr'] ; 
    		$sql ='';
    		if(in_array( strtoupper($fisscr), [ 'HPSCR' , 'LPSCR','ISCR' ])){
    			$db = 'gz_YjzSCREGRNOcbHZ' ;
    			$sql =" select * from {$db}  where 1=1 and fbillno = '{$fjybjbillno}' " ;
    		}
    		$result=[];
    		$data = SqlServerUtil::execTosqlOK($this->SqlServer,$sql);
    		if($data){
    			$result = arraykeyToLower($data);
    		}
    		showMsg(0,'成功',$result) ; 
    	}
    	//EGR增加的生产成本 27012	fEGRAmount 
    	if(in_array($FRepKey, [ '27012' ])){     
    		$rows = $request->row ;
    		$fjybjbillno =   $rows['fbillno'] ;
    		$fmodel =   $rows['fmodel'] ;
    		$fisscr =   $rows['fisscr'] ;
    		$fisegr =   $rows['fisegr'] ;
    		$sql ='';
    		if(in_array($fisegr, [ 'EcoEGR'  ])){
    			$db =  'gz_YjzECOEGRNOcbHZ';
    			$sql =" select * from {$db}  where 1=1 and fbillno = '{$fjybjbillno}' " ;
    		}
    		
    		if( in_array($fisegr, [ 'EGRBP'  ])  ){
    			$db = 'gz_YjzSCREGRNOcbHZ' ;
    			$sql =" select * from {$db}  where 1=1 and fbillno = '{$fjybjbillno}' " ;
    		}
    		$result=[];
    		$data = SqlServerUtil::execTosqlOK($this->SqlServer,$sql);
    		if($data){
    			$result = arraykeyToLower($data);
    		}
    		showMsg(0,'成功',$result) ;
    	}
    	
    	
    	// 26024 --船检固定 
    	if(in_array($FRepKey, [ '26024' ])){
    		$chuansheji  = $request->fchuansheji ; 
    		if( in_array( $chuansheji , ['CCS','ABS','LR','BV','DNV','NK' ] )){
    			$db = 'gz_YchuanjianfDNV_BAOJIA';
    			$sql =" select row_number() over(order by v1.fid desc ) as rownumber ,v1.fid,v1.fmodel,v1.fchuanjishe, v1.fzjjianyanf,
    			v1.fnoxpaifangf,v1.flvtuf,v1.fjizuojijiaf,v1.fzhusuf,v1.fchuchaibutie,	v1.franyouf,v1.fguoluf,v1.fzhengshuf,v1.fpaifangtestf,
    			v1.fzztaxAmount,v1.fallamount,v1.fchanjianfeiDNV,
    			v1.fcreatetime, v1.FStatus, v1.checkName ,t2.fbrand,t2.fmoli  as fmali,t2.fzhuansu,t2.fpower ,t2.funit   ,u1.fqty as fsxqty
    			from {$db}   v1
    			left join gz_YBaseSC u1 on u1.fbillno =v1.fjybjbillno
    			left join  gz_YBaseJS t2 on  t2.fmodel = v1.fmodel
    			where 1=1 and v1.fjybjbillno = '{$fjybjbillno}' " ;
    			
    			if( $chuansheji  != 'DNV' ){
    				$db = 'gz_Ychuanjianfgd';
    				$sql =" select v1.* ,u1.fqty as fsxqty from {$db} v1 left join gz_YBaseSC u1 on u1.fbillno =v1.fjybjbillno
    				where 1=1 and v1.fjybjbillno = '{$fjybjbillno}' " ;
    			}
    			
    		}else{
    			$sql =" select v1.* ,v1.FSetCJSQTAmount as fsetcjsbvamount ,u1.fqty as fsxqty from gz_YchuanjianfQT v1 left join gz_YBaseSC u1 on u1.fbillno = v1.fjybjbillno
    			where 1=1 and  v1.fjybjbillno = '{$fjybjbillno}' " ;
    		}
    	 
    		$result=[];
    		$data = SqlServerUtil::execTosqlOK($this->SqlServer,$sql);
    		if($data){
    			$result = arraykeyToLower($data);
    		}
    		showMsg(0,'成功',$result) ; 
    	}
    	
    	$sql =" select * from {$db}  where 1=1 and fjybjbillno = '{$fjybjbillno}' " ;
//     	    	echo $sql;die;
    	$data = SqlServerUtil::execTosqlOK($this->SqlServer,$sql);
    	$result=[];
    	if($data){
    		$result = arraykeyToLower($data);
    	}
    	showMsg(0,'成功',$result) ; 
    }
    
    
    /**
          正式报价(后续)  -- 明细 加账 
    * @date: 2024年7月8日 下午7:26:06
    * @author: Administrator
    */
    public function getBAOJIAMXQdht(Request $request){
        $FRepKey = $request->get('FRepKey');
        $opername = $request->get('opername');
        $fbrand = $request->get('fbrand');
        $fmodel = $request->get('fmodel');
        $fjybjbillno = $request->get('fjybjbillno');
        $fbillnoentry= $request->get('fbillnoentry');
        
        
        if($FRepKey  == '26005'){
            //采购部
            $bumenName ="采购";
            $bumenStr=" and ( charindex('{$bumenName}',v1.fdanweibumen)>0   )" ;
            $baseSql =" select v1.fbrand as '品牌',v1.fcode as '代码',v1.fprodno as '机型',v1.fname as '名称',v1.fywqty as '数量',
            v1.foriamount as  N'单价',v1.fallAmount as  N'金额'   from gz_Yjiazhangcbf_HouXu_BAOJIA v1  
            where 1=1 and v1.fbillnoentry = '{$fbillnoentry}'  {$bumenStr} " ;
            
        }elseif($FRepKey == '26023'){
            //技术中心
            $bumenName ="技术";
            $bumenStr=" and ( charindex(N'{$bumenName}',v1.fdanweibumen)>0   )" ;
            //,v1.fallamount as  N'金额'
            $baseSql =" select v1.fbrand as  N'品牌',v1.fcode as  N'代码',v1.fprodno as  N'机型',v1.fname as  N'名称',
            v1.fywqty as  N'数量',v1.foriamount as  N'单价',v1.fsxQty as  N'生效台数' ,v1.fallAmount as  N'金额'  from gz_Yjiazhangcbf_HouXu_BAOJIA v1  
            where 1=1 and v1.fbillnoentry = '{$fbillnoentry}'  {$bumenStr} " ;
            
        }elseif($FRepKey  == '26025'){
            //其他部门    =  售后服务部、生产管理部  ， 质量管理部
            $bumenName ="售后";
            $bumenName1 ="生产";
            $bumenName2 ="质量";
            $bumenName3 ="其他";
            $bumenStr=" and ( charindex('{$bumenName}',v1.fdanweibumen)>0  or charindex('{$bumenName1}',v1.fdanweibumen)>0 or charindex('{$bumenName2}',v1.fdanweibumen)>0 or charindex('{$bumenName3}',v1.fdanweibumen)>0  )" ;
            $baseSql =" select select v1.fbrand as  N'品牌',v1.fcode as  N'代码',v1.fprodno as  N'机型',v1.fname as  N'名称',
            v1.fywqty as  N'数量',v1.foriamount as  N'单价',v1.fsxQty as  N'生效台数' ,v1.fallAmount as  N'金额'  
            from gz_Yjiazhangcbf_HouXu_BAOJIA v1  where 1=1 and v1.fbillnoentry = '{$fbillnoentry}'  {$bumenStr} " ;
        }
        
//         echo  $baseSql ;die;
        $res = SqlServerUtil::execTosqlOKTO($this->SqlServer,  $baseSql);
        //     			dd($res);
        $result =[];
        if($res){
            $result = arraykeyToLower($res);
            foreach ($result as $k1=>&$v1)
            {
                foreach ($v1 as $k2=>$v2)
                {
                    if( $v1[$k2] ==='.00' || $v1[$k2]  ==='.0000'  || $v1[$k2]  ==='.000' || $v1[$k2]  ==='.000000' || ($v1[$k2]>0 && $v1[$k2]<1) ){
                        $v1[$k2] = floatval($v2);
                    }
                }
            }
        }
        showMsg(0,'成功' , $result) ;
        
        
    }
    
    
    /**
    * 正式报价 -采购 技术 财务 加账明细 
    * @date: 2023年4月9日 下午2:47:21
    * @author: juyi
    */
    public function getJZBAOJIAMX(Request $request){
    	$FRepKey = $request->get('FRepKey');
    	$opername = $request->get('opername');
    	$fbrand = $request->get('fbrand');
    	$fmodel = $request->get('fmodel');
    	$fjybjbillno = $request->get('fjybjbillno');
    	$fjzdetail = $request->get('fjzdetail')??0;
//     	$db = columnBiao($FRepKey) ;
 
    	if($FRepKey  == '14009'){
    		//业务需求 加账
    		$baseSql ="  select  u1.fbrand as N'品牌',v1.fcode as N'代码',v1.fprodno as N'机型',u1.fname as N'名称',v1.fywqty as N'数量' ,u1.fzjQty as N'单位'
    		,v1.fnote as '备注' from gz_Yjiazhangcbf v1  left join gz_YjiazhangcbfSet u1 on u1.fcode =  v1.fcode
    		where 1=1 and v1.fbillno = '{$fjybjbillno}' ";
    		
    	}elseif($FRepKey  == '14011'){
    		//技术 14011
    		$baseSql ="  select  u1.fbrand as N'品牌',v1.fcode as N'代码',v1.fprodno as N'机型',
    		u1.fname as N'名称',u1.fzjQty as N'单位',v1.fywqty as N'数量' ,t1.fallAmount as N'金额' 
			,u1.fdanweibumen as '部门'
    		from gz_Yjiazhangcbf v1  left join gz_YjiazhangcbfSet u1 on u1.fcode =  v1.fcode
    		left join gz_YjiazhangcbfMX  t1 on t1.fcode = v1.fcode  and t1.fprodno = v1.fprodno
    		where 1=1 and v1.fbillno = '{$fjybjbillno}' and  ( charindex('技术',u1.fdanweibumen)>0 ) ";
    		
    	}elseif($FRepKey  == '14012'){
    		//采购 14012
    		$baseSql ="  select  u1.fbrand as N'品牌',v1.fcode as N'代码',v1.fprodno as N'机型',
    		u1.fname as N'名称',u1.fzjQty as N'单位',v1.fywqty as N'数量'  ,t1.fallAmount as N'金额'
			,u1.fdanweibumen as '部门'
    		from gz_Yjiazhangcbf v1  left join gz_YjiazhangcbfSet u1 on u1.fcode =  v1.fcode
    		left join gz_YjiazhangcbfMX  t1 on t1.fcode = v1.fcode  and t1.fprodno = v1.fprodno
    		where 1=1 and v1.fbillno = '{$fjybjbillno}' and  ( charindex('采购',u1.fdanweibumen)>0 ) ";
    		
    	}elseif($FRepKey  == '14013'){
    		//财务 14013
    		$baseSql ="  select  u1.fbrand as N'品牌',v1.fcode as N'代码',v1.fprodno as N'机型',
    		u1.fname as N'名称',u1.fzjQty as N'单位',v1.fywqty as N'数量'  ,t1.fallAmount as N'金额'
			,u1.fdanweibumen as '部门'
    		from gz_Yjiazhangcbf v1  left join gz_YjiazhangcbfSet u1 on u1.fcode =  v1.fcode
    		left join gz_YjiazhangcbfMX  t1 on t1.fcode = v1.fcode  and t1.fprodno = v1.fprodno
    		where 1=1 and v1.fbillno = '{$fjybjbillno}' and  ( charindex('其他',fdanweibumen)>0  or charindex('生产',fdanweibumen)>0  or charindex('质量',fdanweibumen)>0  or charindex('售后',fdanweibumen)>0  ) ";
    		
    	}
    	
    	$res = SqlServerUtil::execTosqlOKTO($this->SqlServer,  $baseSql);
    	// dd($res);
    	$result =[];
    	if($res){
    		$result = arraykeyToLower($res);
    		foreach ($result as $k1=>&$v1)
    		{
    			foreach ($v1 as $k2=>$v2)
    			{
    				if( $v1[$k2] ==='.00' || $v1[$k2]  ==='.0000'  || $v1[$k2]  ==='.000' || $v1[$k2]  ==='.000000' || ($v1[$k2]>0 && $v1[$k2]<1) ){
    					$v1[$k2] = floatval($v2);
    				}
    				// fnbfhyx
    			}
    		}
    	}
    	showMsg(0,'成功' , $result) ;
    	
    }
    
    
    /**
    * 正式报价 -采购 技术 财务  机型详情  
    * @date: 2023年4月9日 下午2:52:58
    * @author: juyi
    */
    public function getJZBAOJIAMXDetail(Request $request){
    	$FRepKey = $request->get('FRepKey');
    	$opername = $request->get('opername');
    	$fbrand = $request->get('fbrand');
    	$fmodel = $request->get('fmodel');
    	$fjybjbillno = $request->get('fjybjbillno');
    	$fjzdetail = $request->get('fjzdetail')??0;
    	
    	if(empty($fmodel)){
    		showMsg(400,'机型参数错误');
    	}
    	$sql = "select fbrand  from gz_Ybasejs where  fmodel='{$fmodel}'  " ;
    	$jsData = SqlServerUtil::execToSql($this->SqlServer,$sql,2);
    	
    	$fbrand = $jsData['fbrand'];
    	$fmodelStr = "";
    	$fmodelStr1 = "";
    	 
    	$fmodelStr ="  and  u1.fprodno ='{$fmodel}'  ";
    	$fmodelStr1="  and  u1.fprodno =''{$fmodel}''  ";
    	 
    	
    	if( in_array($FRepKey, [ '26005', '14012'     ]) ) {
    		//加账清单加账清单(采购)
    		// -- 1=1  可以替换成 u1.fbrand='WINGD'
    		// -- 2=2  可以替换成 u1.fbrand= ''WINGD''
    		$fdanweibumenStr= " 2=2 and charindex(''采购'',v1.fdanweibumen)>0  " ;
    		$fdanweibumenStr =   iconv('UTF-8', 'GBK', $fdanweibumenStr);
    		
    		$fbmjscgStr = " and charindex('采购',v1.fdanweibumen)>0  " ;
    		$fbmjscgStr =   iconv('UTF-8', 'GBK', $fbmjscgStr);
    	}
    	
    	if( in_array( $FRepKey, [ '26023', '14011'    ]) ) {
    		//加账清单(技术)
    		$fdanweibumenStr= " 2=2 and charindex(''技术'',v1.fdanweibumen)>0  " ;
    		$fdanweibumenStr =   iconv('UTF-8', 'GBK', $fdanweibumenStr);
    		
    		$fbmjscgStr = " and charindex('技术',v1.fdanweibumen)>0  " ;
    		$fbmjscgStr =   iconv('UTF-8', 'GBK', $fbmjscgStr);
    	}
    	
    	if( in_array( $FRepKey, [ '26025', '14013'   ]) ) {
    		//加账清单(其他) 
    		$bumenName ="售后";
    		$bumenName1 ="生产";
    		$bumenName2 ="质量";
    		$fdanweibumenStr= " 2=2 and (charindex(''售后'',v1.fdanweibumen)>0  or charindex(''生产'',v1.fdanweibumen)>0 or charindex(''质量'',v1.fdanweibumen)>0 ) " ;
    		$fdanweibumenStr =   iconv('UTF-8', 'GBK', $fdanweibumenStr);
    		
    		$fbmjscgStr = " and ( charindex('售后',v1.fdanweibumen)>0 or charindex('生产',v1.fdanweibumen)>0 or charindex('质量',v1.fdanweibumen)>0 )   " ;
    		$fbmjscgStr =   iconv('UTF-8', 'GBK', $fbmjscgStr);
    	}
    	$sql = " set nocount on
    	if object_id('tempdb..#tmpprodno') is not null drop table #tmpprodno
    	create table #tmpprodno(
    	fid int identity(1,1),
    	fprodno varchar(200)
    	)
    	insert into #tmpprodno(fprodno)
    	select u1.fprodno from gz_YjiazhangcbfMX  u1  inner join gz_YjiazhangcbfSet v1 on v1.fcode= u1.fcode
    	where  v1.fbrand='{$fbrand}' {$fmodelStr}  {$fbmjscgStr} group by u1.fprodno
    	declare @sqlmax varchar(max),@filvalue varchar(200)
    	declare @i int ,@rwcount int
    	set @i=1
    	select @rwcount=count(1) from #tmpprodno
    	set @sqlmax='select u1.fcode as ''代码'', min(v1.fzjqty) as ''单位'',min(v1.fname) as ''名称'' '
    	while @i<=@rwcount
    	begin
    	select @filvalue=fprodno from #tmpprodno where fid=@i
    	set @sqlmax=@sqlmax+',sum(case when u1.fprodno='''+@filvalue+''' then fallAmount else 0 end) as ['+ @filvalue +']'
    	set @i=@i+1
    	end
    	set @sqlmax=@sqlmax+ ' from gz_YjiazhangcbfMX  u1 inner join gz_YjiazhangcbfSet v1 on u1.fcode=v1.fcode
    	where 2=2 and v1.fbrand=''{$fbrand}''  {$fmodelStr1}  group by u1.fcode '
    	exec( @sqlmax) ";
    	
    	// 	echo $sql ;die;
    	$sql = str_replace('2=2',$fdanweibumenStr ,$sql );
    	
    	// echo $sql ;die;
    	$data = SqlServerUtil::execTosqlYes($this->SqlServer, $sql );
    	//dd($data);
    	if($data){
    		foreach ($data as $k => &$v)
    		{
    			foreach ($v as $k1=>$v1)
    			{
    				if( $v[$k1] ==='.00' || $v[$k1] ==='.000' || $v[$k1] ==='.0000' || ($v[$k1]>0 && $v[$k1]<1)  ){
    					$v[$k1] = floatval($v1);
    				}
    			}
    		}
    	}
    	showMsg(0,'成功' ,$data );
    }
    	
    
    
    
    /**
     *  经营报价 ZLC  --  经营报价 
     * @date: 2023年1月9日 下午3:43:44
     * @author: juyi
     */
    public function yuSuanZLCJYBJ(Request $request){ 
    	$keyword = $request->keyword;
    	$fbrand = $request->fbrand;
    	$fsheji = $request->fsheji??0; //设计经营
    	 
    	$keywordStr="";
    	if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
    		$keyword =  $request->keyword ;
    		$keywordTmp = explode(',',$keyword);
    		if(count($keywordTmp)>1){
    			$tmp30004 = '';
    			foreach ($keywordTmp as $v)
    			{
    				$tmp30004 .= " or charindex('{$v}',v1.Fmodel)>0 or charindex('{$v}',v1.Fbillno)>0  " ;
    			}
    			$keywordStr=' and ( '.trim($tmp30004 ,' or') .")";
    		}else{
    			$keywordStr=" and ( charindex('{$keyword}',v1.Fmodel)>0 or charindex('{$keyword}',v1.Fbillno)>0  )";
    		}
    	}
    	$fbrandStr="";
    	if ($request->has('fbrand') and $request->fbrand != '' and !empty($request->fbrand)) {
    		$fbrand =  $request->fbrand ;
    		$fbrandStr=" and v1.fbrand = '{$fbrand}'  ";
    	}

    	//参数值
    	$CsData =  $this->getSystemProfile();
    	//税率
    	$fax = $CsData['fsetffax']/100;
    	$faxff = $CsData['fsetffax'];
    	
    	//税率
    	$ww_113 = 1+$fax ;
    	//委外
    	$ww_103 = $CsData['fsetweiwaif'] ;    	$ww_10000 = $CsData['fsetprodfy'] ;
    	$ww_10 = $CsData['fsetprodgzftts'] ;   	$ww_5 = $CsData['fsetprodxhdjftts'] ;
    	//图纸送审
    	$ww_106 = $CsData['fsettuzhiss'] ;
    	//运保费
    	$ww_109 = $CsData['fsetyunbaof'] ;
    	//财务
    	$ww_005 = $CsData['fsetsfcwglfy'] ;
    	$ww_005gl = $CsData['fsetglfy'] ;
    	 
    	$sql ="  select v1.fbillno,  v1.fqty ,v1.fmodel ,v1.fbrand,v1.fpower ,0 as fisqr,
    	u1.funit,u1.ffuliaopakeage,(u1.fhanjiegs + u1.fjijiags + u1.fzhuangshigs ) as fworkhour , 
		u1.fSCRgs as fworkhourScr , u1.fEGRgs as  fworkhourEgr ,

    	Round(isnull( cgcb.fallAmount, 0 )* {$ww_113},2)  as  ftaxSinglezjcl,
    	
    	Round(isnull(zl.fPatentfeeAmount,0)*zl.fsetzhaunlifeibl*v1.fpower* {$ww_113},2)   as fPatentfee,
    	Round(isnull(cjccs.fchanjianfeiCCS,0)*{$ww_113},2) as fshipfeeCCS,
    	Round(isnull(cjabs.fchanjianfeiABS,0)*{$ww_113} ,2) as fshipfeeABS,
    	Round(isnull(cjlr.fchanjianfeiLR,0)*{$ww_113} ,2) as fshipfeeLR,
    	Round(isnull(cjbv.fchanjianfeiBV,0)*{$ww_113},2) as fshipfeeBV,
    	Round(isnull(cjnk.fchanjianfeiNK,0)*{$ww_113},2) as fshipfeeNK,
    	Round(isnull(cjdnv.fchanjianfeiDNV,0)*{$ww_113},2)  as fshipfeeDNVGL,
       
    	Round(isnull(yq.fAllamount,0)* {$ww_113} ,2)  as fyouqifee,

    	isnull(pfcs.fallAmount,0)* {$ww_113} as  femissionfee,
    	Round(isnull(tz.fallAmount,0)* {$ww_113}/5,2)  as fDrawingfee,

    	isnull(zlcb.fallAmount,0) as fqualityCost,
    	Round((isnull(prod.fweiwaiAmount,0)*{$ww_10000}/{$ww_103})* $ww_113 ,2) as fweiwaifee,
    	round(((prod.fhanjiegz +prod.fjijiagz +prod.fzhuangshigz +prod.fshichegz)/{$ww_10} +prod.ffayungzzj)*{$ww_10000},2)  as fworkwhole,
    	round(((prod.fhanjiegz +prod.fjijiagz +prod.fzhuangshigz +prod.fshichegz)/{$ww_10} +prod.ffayungzfd)*{$ww_10000},2)  as fworkparted,
    	Round(isnull(prod.fxjxtsdaoju,0)*{$ww_10000}/{$ww_5} ,2)  as fcutter ,
    	
    	Round(isnull(fjhj.fallamount ,0)*{$ww_113},2) as fweldWorkfc ,
    	Round(isnull(fjjj.fallamount ,0) ,2) as fmachineWorkfc,
    	Round(isnull(fjzs.fallamount ,0)*{$ww_113},2) as  ftestWorkfc,
    	0 as ffucaitotal,
    	
    	Round(isnull(sd.fjgcjDWAmount,0) + isnull(sd.fhanjiecj,0) ,2) as  fweldWorksd ,
    	Round(isnull(sd.fjijiacj,0),2)  as  fmachineWorksd ,
    	Round(isnull(sd.fzhuangshicj,0),2)  as ftestWorksd ,
    	0  as fsdTotal,
    	
    	Round(isnull(u1.ftuzhissCCS,0)*{$ww_113},2) as fDrawingCCS ,
    	Round(isnull(u1.ftuzhissABS,0)*{$ww_113} ,2) as fDrawingABS ,
    	Round(isnull(u1.ftuzhissLR,0)*{$ww_113} ,2) as fDrawingLR ,
    	Round(isnull(u1.ftuzhissBV,0)*{$ww_113} ,2) as fDrawingBV ,
    	Round(isnull(u1.ftuzhissNK,0)*{$ww_113} ,2) as fDrawingNK ,
    	Round(isnull(u1.ftuzhissDNVGL,0)*{$ww_113} ,2) as fDrawingDNVGL ,
    	
    	isnull(u1.fniuzhenRMB,0)  AS fniuzhenjisuanfee,
    	Round(isnull(yb.fallAmount,0)/{$ww_109}*{$ww_113},2) AS fyunfei,
    	isnull(shts.fallAmount,0) as fsaleCost ,
    	
    	0 as fsczlCost ,
		
    	Round(u1.fhanjiegs *u1.fhanjiePrice*{$ww_113} ,2)  as fweldRg ,
    	Round(u1.fjijiags * u1.fjijiaPrice*{$ww_113},2)  as fjjgRg ,
    	Round(u1.fzhuangshigs * u1.fzhuangshiPrice*{$ww_113},2) as fzhuangshiRg ,
    	0 as fzhijieRg ,
 		Round(isnull(zj.fcjZjAmount,0)*{$ww_113} ,2) as fzhejiu ,
    	0  as fSCRCost ,
    	0  as fEGRCost ,
    	
    	0 as fscrIncWork ,
    	0 as fscrIncSD ,
    	0 as fNooneyouqifee,
    	
    	0 as fsingleProdCostCCS ,0 as fsingleProdCostABS ,0 as fsingleProdCostLR ,0 as fsingleProdCostDNVGL ,0 as fsingleProdCostBV ,0 as fsingleProdCostNK  ,
    	0 as fcwsingleProdCostCCS ,0 as fcwsingleProdCostABS ,0 as fcwsingleProdCostLR ,0 as fcwsingleProdCostDNVGL ,0 as fcwsingleProdCostBV ,0 as fcwsingleProdCostNK
    	
    	from
		gz_YbaojiadanZLCCG v1 
    	inner JOIN gz_YBaseJS_ZLCCG u1 on v1.fbillno = u1.fjybjbillno  
    	LEFT JOIN (SELECT SUM(fallAmount ) fallAmount,fjybjbillno FROM gz_Ycaigoucbf_ZLCCG GROUP BY fjybjbillno) cgcb on cgcb.fjybjbillno = v1.fbillno
    	left join gz_YBaseProduce_ZLCCG prod on prod.fjybjbillno = v1.fbillno

		LEFT JOIN gz_YchuanjianfCCS_ZLCCG  cjccs on cjccs.fjybjbillno= v1.fbillno   and  cjccs.fchuanjishe = 'CCS'
    	LEFT JOIN gz_YchuanjianfABS_ZLCCG  cjabs on cjabs.fjybjbillno= v1.fbillno   and   cjabs.fchuanjishe = 'ABS'
    	LEFT JOIN gz_YchuanjianfLR_ZLCCG  cjlr on cjlr.fjybjbillno= v1.fbillno   and  cjlr.fchuanjishe = 'LR'
    	LEFT JOIN gz_YchuanjianfBV_ZLCCG  cjbv on cjbv.fjybjbillno= v1.fbillno   and  cjbv.fchuanjishe = 'BV'
    	LEFT JOIN gz_YchuanjianfNK_ZLCCG  cjnk on cjnk.fjybjbillno= v1.fbillno   and  cjnk.fchuanjishe = 'NK'
    	LEFT JOIN gz_YchuanjianfDNV_ZLCCG  cjdnv on cjdnv.fjybjbillno= v1.fbillno   and  cjdnv.fchuanjishe = 'DNV'
    	
    	left join gz_Yzhiliangcb_ZLCCG zlcb on zlcb.fjybjbillno = v1.fbillno
    	
    	left join gz_Yfucaicbf_ZLCCG  fjhj on fjhj.fjybjbillno = v1.fbillno
    	left join gz_Yfucaicbfjijia_ZLCCG  fjjj on fjjj.fjybjbillno = v1.fbillno
    	left join gz_Yfucaicbfzshi_ZLCCG fjzs on fjzs.fjybjbillno = v1.fbillno
    	
    	left join gz_Yshuidianf_ZLCCG sd on sd.fjybjbillno = v1.fbillno
    	left join gz_Yyunbaof_ZLCCG yb on yb.fjybjbillno = v1.fbillno
    	left join gz_Yshtswhcb_ZLCCG shts on shts.fjybjbillno = v1.fbillno
    	left join gz_Yzhejiuf_ZLCCG zj on zj.fjybjbillno = v1.fbillno

		left join gz_Yyouqif_ZLCCG yq on yq.fjybjbillno = v1.fbillno
		left join gz_Yzhuanlif_ZLCCG zl on zl.fjybjbillno = v1.fbillno
		left join gz_Ypfceshif_ZLCCG pfcs on pfcs.fjybjbillno = v1.fbillno
		left join gz_Ytuzhif_ZLCCG tz on tz.fjybjbillno = v1.fbillno
		where 1=1 and  v1.fisqr>=3 and v1.fcaigouRemark <> ''  and  v1.fjishuRemark <>'' and v1.fcaiwuRemark <>'' {$keywordStr} {$fbrandStr}  
    	and v1.fbillno not in ( select fbillno from gz_YbaojiadanZLC where  FStatus =1)";
//   	echo $sql;die;
    	$res = SqlServerUtil::execToSql($this->SqlServer, $sql );
    	$result =[];
    	//dd($res);
    	if($res ){
    		$result = arraykeyToLower($res);
    		foreach ($result as $k =>&$v)
    		{
    			 //辅材合计
    			$v['ffucaitotal'] = $v['fweldworkfc'] + $v['fmachineworkfc'] + $v['ftestworkfc'] ;
    			//水电合计
    			$v['fsdtotal'] = $v['fweldworksd'] + $v['fmachineworksd'] + $v['ftestworksd'] ;
    			//直接人工成本
    			$v['fzhijierg'] = $v['fweldrg'] + $v['fjjgrg'] + $v['fzhuangshirg'] ;
    			
    			//dd(  $v['ftaxsinglezjcl']  );
    			//整体单台产品成本（ccs)
    			$v['fsingleprodcostccs'] = $v['ftaxsinglezjcl']+ $v['fpatentfee']+ $v['fshipfeeccs']+ $v['fyouqifee']
    			+ $v['femissionfee']+ $v['fdrawingfee']+ $v['fqualitycost']+ $v['fweiwaifee']+ $v['fworkwhole']
    			+ $v['fcutter']+ $v['ffucaitotal']+ $v['fsdtotal']+ $v['fdrawingccs']
    			+ $v['fyunfei']+ $v['fsalecost']+ $v['fzhijierg']   ;
    			
    			//     	dd($v['fsingleprodcostccs'] , $v['ftaxSinglezjcl'],$v['fpatentfee'],$v['fshipfeeccs'],$v['fyouqifee']
    			//     	,$v['femissionfee'],$v['fdrawingfee'],$v['fqualitycost'],$v['fweiwaifee'],$v['fworkwhole']
    			//     	,$v['fcutter'],$v['ffucaitotal'],$v['fsdtotal'],$v['fdrawingccs'],$v['fniuzhenjisuanfee']
    			//     	,$v['fyunfei'],$v['fsalecost'],$v['fzhijierg']);
    			//整体单台产品成本（abs)
    			$v['fsingleprodcostabs'] =  $v['ftaxsinglezjcl']+ $v['fpatentfee']+ $v['fshipfeeabs']+ $v['fyouqifee']
    			+ $v['femissionfee']+ $v['fdrawingfee']+ $v['fqualitycost']+ $v['fweiwaifee']+ $v['fworkwhole']
    			+ $v['fcutter']+ $v['ffucaitotal']+ $v['fsdtotal']+ $v['fdrawingabs']
    			+ $v['fyunfei']+ $v['fsalecost']+ $v['fzhijierg']   ;
    			//整体单台产品成本（lr)
    			$v['fsingleprodcostlr'] = $v['ftaxsinglezjcl']+ $v['fpatentfee']+ $v['fshipfeelr']+ $v['fyouqifee']
    			+ $v['femissionfee']+ $v['fdrawingfee']+ $v['fqualitycost']+ $v['fweiwaifee']+ $v['fworkwhole']
    			+ $v['fcutter']+ $v['ffucaitotal']+ $v['fsdtotal']+ $v['fdrawinglr']
    			+ $v['fyunfei']+ $v['fsalecost']+ $v['fzhijierg']  ;
    			//整体单台产品成本（dnv)
    			$v['fsingleprodcostdnvgl'] = $v['ftaxsinglezjcl']+ $v['fpatentfee']+ $v['fshipfeednvgl']+ $v['fyouqifee']
    			+ $v['femissionfee']+ $v['fdrawingfee']+ $v['fqualitycost']+ $v['fweiwaifee']+ $v['fworkwhole']
    			+ $v['fcutter']+ $v['ffucaitotal']+ $v['fsdtotal']+ $v['fdrawingdnvgl']
    			+ $v['fyunfei']+ $v['fsalecost']+ $v['fzhijierg'] ;
    			//整体单台产品成本（bv)
    			$v['fsingleprodcostbv'] = $v['ftaxsinglezjcl']+ $v['fpatentfee']+ $v['fshipfeebv']+ $v['fyouqifee']
    			+ $v['femissionfee']+ $v['fdrawingfee']+ $v['fqualitycost']+ $v['fweiwaifee']+ $v['fworkwhole']
    			+ $v['fcutter']+ $v['ffucaitotal']+ $v['fsdtotal']+ $v['fdrawingbv']
    			+ $v['fyunfei']+ $v['fsalecost']+ $v['fzhijierg'] ;
    			//整体单台产品成本 nk
    			$v['fsingleprodcostnk'] =  $v['ftaxsinglezjcl']+ $v['fpatentfee']+ $v['fshipfeenk']+ $v['fyouqifee']
    			+ $v['femissionfee']+ $v['fdrawingfee']+ $v['fqualitycost']+ $v['fweiwaifee']+ $v['fworkwhole']
    			+ $v['fcutter']+ $v['ffucaitotal']+ $v['fsdtotal']+ $v['fdrawingnk']
    			+ $v['fyunfei']+ $v['fsalecost']+ $v['fzhijierg'] ;
    			
    			//税费及财务费用   = 整体单台产品成本（ccs)  *5%
    			//整体单台产品成本（ccs)
    			$v['fcwsingleprodcostccs'] = $v['fsingleprodcostccs'] *$ww_005 ;
    			//整体单台产品成本（abs)
    			$v['fcwsingleprodcostabs'] =  $v['fsingleprodcostabs'] *$ww_005 ;
    			//整体单台产品成本（lr)
    			$v['fcwsingleprodcostlr'] = $v['fsingleprodcostlr'] *$ww_005 ;
    			//整体单台产品成本（dnv)
    			$v['fcwsingleprodcostdnvgl'] = $v['fsingleprodcostdnvgl'] *$ww_005 ;
    			//整体单台产品成本（bv)
    			$v['fcwsingleprodcostbv'] =$v['fsingleprodcostbv'] *$ww_005 ;
    			//整体单台产品成本 nk
    			$v['fcwsingleprodcostnk'] =  $v['fsingleprodcostnk'] *$ww_005 ;
    			
    			// 管理费用  =   5% *( 税费及财务费用 + css )
    			$v['fglfyccs'] =  ($v['fsingleprodcostccs'] + $v['fcwsingleprodcostccs']) *$ww_005gl ;
    			$v['fglfyabs'] =   ($v['fsingleprodcostabs'] + $v['fcwsingleprodcostabs']) *$ww_005gl ;
    			$v['fglfylr'] =   ($v['fsingleprodcostlr'] + $v['fcwsingleprodcostlr']) *$ww_005gl ;
    			$v['fglfydnv'] =   ($v['fsingleprodcostdnvgl'] + $v['fcwsingleprodcostdnvgl']) *$ww_005gl ;
    			$v['fglfybv'] =   ($v['fsingleprodcostbv'] + $v['fcwsingleprodcostbv']) *$ww_005gl ;
    			$v['fglfynk'] =   ($v['fsingleprodcostnk'] + $v['fcwsingleprodcostnk']) *$ww_005gl ;
    			
    			//变动成本小计 = 小计（css） + 税费及财务费用 + 管理费用 ；
    			$v['fbdcbccs'] =  $v['fsingleprodcostccs'] + $v['fcwsingleprodcostccs'] + $v['fglfyccs'] ;
    			$v['fbdcbabs'] =  $v['fsingleprodcostabs'] + $v['fcwsingleprodcostabs'] + $v['fglfyabs'] ;
    			$v['fbdcblr'] =  $v['fsingleprodcostlr'] + $v['fcwsingleprodcostlr'] + $v['fglfylr'] ;
    			$v['fbdcbdnv'] =  $v['fsingleprodcostdnvgl'] + $v['fcwsingleprodcostdnvgl'] + $v['fglfydnv'] ;
    			$v['fbdcbbv'] =  $v['fsingleprodcostbv'] + $v['fcwsingleprodcostbv'] + $v['fglfybv'] ;
    			$v['fbdcbnk'] =  $v['fsingleprodcostnk'] + $v['fcwsingleprodcostnk'] + $v['fglfynk'] ;
    			
    			//总成本费用  =  变动成本小计 + 折旧
    			$v['fzcbfyccs'] =  $v['fbdcbccs']  +  $v['fzhejiu']  ;
    			$v['fzcbfyabs'] =  $v['fbdcbabs']  +  $v['fzhejiu']   ;
    			$v['fzcbfylr'] =   $v['fbdcblr']  +  $v['fzhejiu']   ;
    			$v['fzcbfydnv'] =  $v['fbdcbdnv']  +  $v['fzhejiu']   ;
    			$v['fzcbfybv'] =   $v['fbdcbbv']  +  $v['fzhejiu']   ;
    			$v['fzcbfynk'] =   $v['fbdcbnk']  +  $v['fzhejiu']   ;
    			
    			foreach ($v as $k1=>$v1)
    			{
    				if( $v[$k1] ==='.00' ||  $v[$k1] ==='.0000' ||  $v[$k1] ==='.000' || ($v[$k1]>0 && $v[$k1]<1)  ){
    					$v[$k1] = floatval($v1);
    				}
    			}
    			
    		}
    		
    	}
    	
    	showMsg(200,'成功',$result );
    	
    }
    
    /**
     *  经营报价   Save 保存      -- 经营报价
     * @date: 2022年12月23日 下午5:51:33
     * @author: juyi
     */
    public function yuSuanZLCJYBJSave(Request $request){
    	$param = $request ->get('selectedData') ;
    	$opername = $request ->opername ;
    	$FRepKey = $request ->FRepKey ;
    	if($FRepKey == 30009){
    		$db ="gz_YbaojiadanZLCXC";
    	}else{
    		$db = 'gz_YbaojiadanZLC'; //30004
    	}
    	if(empty($param)){
    		showMsg(400,'保存数据不能为空');
    	}
    	
    	$data = $param ;
    	//字符串
    	$fbillno =join("','", array_column($data, 'fbillno'));
    	$fbillnoStr = "'".$fbillno ."'";
    	
    	$delete = sqlsrv_query($this->SqlServer, "delete from {$db} where  fbillno in ({$fbillnoStr}) ");
    	
    	if(count($data)>400){
    		$each=400;
    		$total =count($data); //数据总数
    		$step=ceil($total/$each); //insert执行总次数
    		$j = 1;
    		$s = $step;
    		foreach ($data as $k=>&$v)
    		{
    			$v['fcreateManager'] = $opername;
    			$arr0=[];$Tmp0 =[];
    			if($j > $step) break;
    			$arr0 = array_slice($data, ($step - $s) * $each, $each);     // 每次取500条
    			
    			$qkid =SqlServerUtil::sqlsrvAllTosql($this->SqlServer, $db ,$arr0);
    			$j++;
    			$s--;
    		}
    		
    	}else{
    		$tempNew =[];
    		$tempNew = getArrayWalkData($param , ['fcreatemanager' => $opername]);
    		$qkid =SqlServerUtil::sqlsrvAllTosql($this->SqlServer, $db ,$tempNew);
    		$this->writeLog(getMkName($FRepKey),'删除' , $FRepKey , $data ,$opername);
    	}
    	
    	showMsg(200,'保存成功');
    }
    
    /**
    * 签订合同 创建子流水号
    * @date: 2023年3月8日 上午1:26:17
    * @author: juyi
    */
    public function QdhtBaojia(Request $request){
    	//
    	$opername = $request ->opername ;
    	$FRepKey = $request ->FRepKey ;
    	$data = $request->data;
    	$db = columnBiao($FRepKey) ;
    	if(empty($data)){
    		showMsg(400,'未选中数据信息') ;
    	}
    	$fbillno = $data['fbillno'] ;
    	//判断当前是否已经存在
    	if($FRepKey =='34001' ){
    		$hao = '-JZ001';
    	}else{
    		//30010  -- 市场需求(后续)
    		$hao = '-001';
    	}
    	
    	$fbillnoEntry = $fbillno.$hao;
    	//判断是否有存在子流水号
    	$baseSql = "select max(RIGHT(fbillnoentry,3)) fbillnoentry from $db where fbillno = '{$fbillno}' " ;
//     	echo $baseSql;die;
    	$res = SqlServerUtil::execToSql($this->SqlServer,  $baseSql,2);
    	if(!empty($res['fbillnoentry'])){
    		if($FRepKey == '34001' ){
    			$fbillnoEntry = $fbillno .'-JZ'.str_pad(intval($res['fbillnoentry'])+1, 3,0,STR_PAD_LEFT)  ;
    		}else{
    			$fbillnoEntry = $fbillno .'-'.str_pad(intval($res['fbillnoentry'])+1, 3,0,STR_PAD_LEFT)  ;
    		}
    	}
    	
    	$QDHTTemp = $this->getQDHTQR($fbillno, '14009',$fbillnoEntry ,$FRepKey  );
    	if($QDHTTemp){
    		// SqlServerUtil::sqlsrvDeleteBack($this->SqlServer, $db , ['fjybjbillno'=> "'".$v['fbillno']."'" ],true);
    		SqlServerUtil::sqlsrvCreate($this->SqlServer , $db  , $QDHTTemp);
    		
    		if($FRepKey =='30010' ){
    			$sql1 = " select v1.* from gz_Yjiazhangcbf v1   where 1=1 and v1.fbillno = '{$fbillno}'  " ;
    			$resCG = SqlServerUtil::execToSql($this->SqlServer, $sql1 );
    			if($resCG){
    				foreach ($resCG as $cjs =>$cjs)
    				{
    					unset($resCG[$cjs]['fid']);
    					unset($resCG[$cjs]['fcreatetime']);
    					$resCG[$cjs]['fbillnoentry'] = $fbillnoEntry ;
    				}
    				SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_Yjiazhangcbf_HouXu' , ['fbillnoentry'=> "'".$fbillnoEntry."'" ],true);
    				SqlServerUtil::sqlsrvAllTosql($this->SqlServer ,'gz_Yjiazhangcbf_HouXu' , $resCG);
    			}
    			
    			$sql2 = " select v1.* from gz_Yjiazhangcbf_BAOJIA v1   where 1=1 and v1.fjybjbillno = '{$fbillno}'  " ;
    			$resBJ = SqlServerUtil::execToSql($this->SqlServer, $sql2 );
    			if($resBJ){
    				foreach ($resBJ as $cjs =>$cjs)
    				{
    					unset($resBJ[$cjs]['fid']);
    					unset($resBJ[$cjs]['fcreatetime']);
    					$resBJ[$cjs]['fbillnoentry'] = $fbillnoEntry ;
    				}
    				SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_Yjiazhangcbf_HouXu_BAOJIA' , ['fbillnoentry'=> "'".$fbillnoEntry."'" ],true);
    				SqlServerUtil::sqlsrvAllTosql($this->SqlServer ,'gz_Yjiazhangcbf_HouXu_BAOJIA' , $resBJ);
    			}
    			
    		}
    	}else{
    		showMsg(400,' 数据信息为空 ') ;
    	}
    	
    	showMsg(0,' 成功') ;
    	
    }
    
    
    /**
    * 签订合同 创建子流水号  -- 加载生成 30011
    * 后续 --   佣金，运保费，赠送条件，专利费 
    * 1. 后续 改造费 取 正式报价 改造费 
    * @date: 2023年3月8日 上午1:27:17
    * @author: juyi
    * @param: variable
    * @return:
    */
    public function ScQdhtBaojia(Request $request){
    	$keywordStr="";
    	if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
    		$keyword =  $request->keyword ;
    		$keywordTmp = explode(',',$keyword);
    		if(count($keywordTmp)>1){
    			$tmp30011 = '';
    			foreach ($keywordTmp as $v)
    			{
    				$tmp30011 .= " or charindex('{$v}',v1.Fmodel)>0 or charindex('{$v}',v1.Fbillno)>0 or charindex('{$v}',v1.fbillnoentry )>0" ;
    			}
    			$keywordStr=' and ( '.trim($tmp30011 ,' or') .")";
    		}else{
    			$keywordStr=" and ( charindex('{$keyword}',v1.Fmodel)>0 or charindex('{$keyword}',v1.Fbillno)>0  or charindex('{$keyword}',v1.fbillnoentry )>0  )";
    		}
    	}
    	$fbrandStr="";
    	if ($request->has('fbrand') and $request->fbrand != '' and !empty($request->fbrand)) {
    		$fbrand =  $request->fbrand ;
    		$fbrandStr=" and u1.fbrand = '{$fbrand}'  ";
    	}
    	
    	//参数值
    	$CsData =  $this->getSystemProfile();
    	//税率
    	$fax = $CsData['fsetffax']/100;
    	//汇率
    	$huilv = $CsData['fsethuilv'];
    	//运保费
    	$ww_109 = $CsData['fsetyunbaof'] ;
    	//税率
    	$ww_113 = 1+$fax ;
    	
    	//财务
    	$ww_005 = $CsData['fsetsfcwglfy'] ;
    	$ww_005gl = $CsData['fsetglfy'] ;
    	//设置置甲醇机管理费用 (正式报价)
    	$jcj_005gl = $CsData['fsetjcjglfy'] ;
    	//设置甲醇机税费及财务费用比例
    	$jcj_005 = $CsData['fsetjcjsfcwglfy'] ;
    	//增加甲醇机的利润率
    	$jcj_005lv = $CsData['fsetjcjlv'] ;
    	
    	
    	
    	
    	$sql="select 
v1.fbillno,v1.fmodel ,v1.fsjpower,v1.fhtpower,v1.fcxpower, v1.fqty,v1.fzlyhAmount
,v1.fmarketprice,0 as fisqr,v1.fisyongjinbl,v1.fchuanjishe,v1.fisjingneijingwai
,v1.fyongjinbl,v1.fyongjinjine,	v1.fyjdate
,v1.fzhibaoqi, v1.fisEGR,v1.fisSCR,v1.fisryrq,v1.fbillnoEntry
,v1.fcustomer ,v1.fcustomerName ,v1.fmodelNO  ,v1.fjsxyNO, v1.fishwtsf
,zs.ffuliaopakeage,	zs.fbrand,zs.funit , zs.ftonnage  
,zs.fworkhour,zs.fworkhourScr,zs.fworkhourEgr
,zl.fsetzhaunlifeibl,zl.ffax as ffaxzl ,zl.fPatentfee as fzlsfbiaozhun,zl.FExchangeRate as fzlhuilv

,Round((isnull(convert(DECIMAL(28,2) ,v1.fyunbaof),0) /{$ww_109}*{$ww_113}),2) AS fyunfei 
,0 asfPatentfee 
,v1.fyongjin 
,v1.fzengsong
		
 ,zs.fhaiwaitsf,zs.ftaxSinglezjcl,zs.fnotaxsinglezjcl 
 ,ISNULL(jzcb.fallAmount,0) as fjiazhangcb,	ISNULL(jzcbcg.fallAmount,0) as fjiazhangcbCG
 ,ISNULL(jzcbqt.fallAmount,0)  as fjiazhangcbQT,ISNULL(jzcbjs.fallAmount ,0) as fjiazhangcbJS
 ,zs.fchuanjianf,zs.fNooneyouqifee,zs.fyouqifee,zs.femissionfee,zs.fDrawingfee
 ,zs.fqualityCost,zs.fweiwaifee ,zs.fworkwhole,zs.fworkparted,zs.fcutter
 ,zs.fweldWorkfc,zs.fmachineWorkfc,zs.ftestWorkfc,zs.ffucaitotal
 ,zs.fweldWorksd,zs.fmachineWorksd,zs.ftestWorksd,zs.fsdTotal,zs.ftuzhiss
 ,zs.fniuzhenjisuanfee,zs.fsaleCost,zs.fweldRg,zs.fjjgRg,zs.fzhuangshiRg,zs.fzhijieRg
 ,zs.fzhejiu,zs.fguanlucbAmount 
 --fyouqifeeTemp	 
 -- fICERRYAmount
 -- fICERRQAmount
 -- fEcoEGRAmount 
 ,zs.fSCRAmount,zs.fEGRAmount,zs.fjiachunAmount,zs.fICERAmount
 ,zs.fEGRCost,zs.fSCRCost,zs.fscrpfcsZS,zs.fscrIncWork,zs.fegrpfcsZS,zs.fgaizaof
 ,zs.fcbzsfzhibaof
 from 
 gz_YBaseSC_QDHT v1
 left join gz_YBaseJS_BAOJIA u1 on v1.fmodel = u1.fmodel  and u1.fjybjbillno = v1.fbillno
 inner join  gz_YbaojiadanCB zs on zs.fbillno = v1.fbillno
 left join gz_Yzhuanlif_QDHT zl on zl.fjybjbillno = v1.fbillno 	AND v1.fbillnoEntry = zl.fbillnoEntry
LEFT JOIN (SELECT SUM(fallAmount ) fallAmount,fbillnoentry  FROM gz_Yjiazhangcbf_HouXu_BAOJIA GROUP BY fbillnoentry) jzcb on jzcb.fbillnoentry = v1.fbillnoentry

LEFT JOIN ( SELECT SUM ( fallAmount ) fallAmount, fbillnoentry  FROM gz_Yjiazhangcbf_HouXu_BAOJIA WHERE Fbm = 'JS' GROUP BY fbillnoentry ) jzcbjs ON jzcbjs.fbillnoentry = v1.fbillnoentry
LEFT JOIN ( SELECT SUM ( fallAmount ) fallAmount, fbillnoentry  FROM gz_Yjiazhangcbf_HouXu_BAOJIA WHERE Fbm = 'CG' GROUP BY fbillnoentry ) jzcbcg ON jzcbcg.fbillnoentry = v1.fbillnoentry
LEFT JOIN ( SELECT SUM ( fallAmount )fallAmount, fbillnoentry FROM gz_Yjiazhangcbf_HouXu_BAOJIA WHERE Fbm = 'QT' GROUP BY fbillnoentry ) jzcbqt ON jzcbqt.fbillnoentry = v1.fbillnoentry
 
 where 1=1 and v1.fstatus =1   {$keywordStr} {$fbrandStr}
		and v1.fbillnoentry not in ( select fbillnoentry from gz_YbaojiadanCB_QDHT  where  FStatus =1)  order by v1.fbillno desc";
    	
//     	echo $sql ;die;
    	$res = SqlServerUtil::execToSql($this->SqlServer, $sql );
    	$result =[];
    	//     	    	dd($res);
    	
        if($res ){
        	    $result = arraykeyToLower($res);
        	    foreach ($result as $k =>&$v)
        	    {
        	        //专利费  --后续
        	        $v['fpatentfee'] = round(getZLBaojia($v['fbrand'],$v['fyjdate'] ,$v['fsetzhaunlifeibl'], $v['fzlsfbiaozhun'],$v['fsjpower'],$v['fzlyhamount'],$v['fzlhuilv'])*$ww_113 ,2);
        	        //佣金
        	        $v['fyongjin'] = getYongjin($v['fmarketprice'] ,$v['fisyongjinbl'], $v['fisjingneijingwai'],$v['fyongjinbl'],$v['fyongjinjine'] ) ;
        	        
        	        //固定部分小计   fworkparted 工装分装
        	        $v['fgdbfxiaoji'] = round($v['ftaxsinglezjcl'] +$v['fyouqifee']+$v['ffucaitotal']+$v['fsdtotal']+$v['fsalecost']
        	            +$v['fqualitycost']+$v['fweiwaifee']+$v['fdrawingfee']+$v['fworkwhole']+$v['fcutter']+$v['fzhijierg'] ,2)  ;
 
        	        //变动部分小计
        	        $v['fbdbfxiaoji'] = round($v['fpatentfee'] +$v['fchuanjianf']+$v['fyunfei']+$v['femissionfee']+$v['ftuzhiss']  ,2) ;
        	        //项目专项成本小计	fxmzxCB
        	        $v['fxmzxcb'] = round($v['fjiazhangcbcg'] +$v['fjiazhangcbjs']+$v['fjiazhangcbqt'] +$v['fscramount']+$v['fegramount']
        	            +$v['ficeramount']+$v['fjiachunamount']+$v['fguanlucbamount'] +$v['fhaiwaitsf']+$v['fyongjin'] +$v['fcbzsfzhibaof']
        	            +$v['fscrpfcszs'] +$v['fegrpfcszs']+$v['fgaizaof']+$v['fzengsong']  ,2)  ;
        	        
        	        //小计  =  项目专项成本小计 + 变动部分小计  + 固定部分小计
        	        $v['fxiaoji'] = round($v['fxmzxcb'] + $v['fbdbfxiaoji'] + $v['fgdbfxiaoji'],2) ;
        	        
        	        //判断是否是甲醇机
        	        if( stripos( strtoupper($v['fmodel']) , 'LGIM' ) !== false)    {
        	            // 税费及财务费用 = (小计+ 折旧费用 ) *设置置甲醇机管理费用 (正式报价) 0.05
        	            $v['fcwfy'] = round(( $v['fxiaoji'] +$v['fzhejiu']) * $jcj_005 ,2);
        	            // 管理费用
        	            $v['fglfy'] =  round(($v['fxiaoji'] +$v['fzhejiu'] + $v['fcwfy'] )* $jcj_005gl ,2) ;
        	            // 变动成本小计 =  小计 + 税费及财务费用   + 管理费用
        	            $v['fbdcb'] = $v['fxiaoji'] + $v['fzhejiu'] + $v['fcwfy'] + $v['fglfy'] ;
        	            // 总成本费用
        	            $v['fzcbfy'] =   round( $v['fbdcb'] * $jcj_005lv ,2) ;
        	            
        	        }else{
        	            // 税费及财务费用 = 小计 *0.05
        	            $v['fcwfy'] = round($v['fxiaoji']  * $ww_005 ,2);
        	            // 管理费用
        	            $v['fglfy'] =  round(($v['fxiaoji'] + $v['fcwfy'] )* $ww_005gl ,2)  ;
        	            // 变动成本小计 =  小计 + 税费及财务费用
        	            $v['fbdcb'] = $v['fxiaoji'] + $v['fcwfy'] + $v['fglfy'] ;
        	            // 总成本费用
        	            $v['fzcbfy'] =   $v['fbdcb'] + $v['fzhejiu'] ;
        	        }
        	        
        	        
        	        unset($v['fyjdate']);
        	        unset($v['fsetzhaunlifeibl']);
        	        unset($v['ffaxzl']);
        	        unset($v['fzlsfbiaozhun']);
        	        unset($v['fzlhuilv']);
        	        
        	        unset($v['fisYongjinbl']);
        	        unset($v['fisjingneijingwai']);
        	        unset($v['fyongjinbl']);
        	        unset($v['fyongjinjine']);
        	        
        	        unset($v['fzhibaoqi']);
        	        //其他成本
        	        unset($v['ficerryamount']);
        	        unset($v['ficerrqamount']);
        	        unset($v['fecoegramount']);
        	        unset($v['fyouqifeetemp']);
        	        
        	        
        	        foreach ($v as $k1=>$v1)
        	        {
        	            if( $v[$k1] ==='.00' ||  $v[$k1] ==='.0000'  ||  $v[$k1] ==='.000' || ($v[$k1]>0 && $v[$k1]<1) ){
        	                $v[$k1] = floatval($v1);
        	            }
        	        }
        	        
        	    }
        	    
        	}
    	
    	showMsg(200,'成功',$result );
    	
    	
    	
    	
    	
    	
    	
    	
    	////////////////////////END
    	
    	
    	
    	//参数值
    	$CsData =  $this->getSystemProfile();
    	//税率
    	$fax = $CsData['fsetffax']/100;
    	//汇率
    	$huilv = $CsData['fsethuilv'];
    	//-气缸单价
    	$qigang = $CsData['fsetqigangprice'];
    	//燃气单价
    	$ranqi = $CsData['fsetranqiprice'];
    	//柴油单价
    	$chaiyou = $CsData['fsetchaiyouprice'];
    	//直接人工
    	$fhanjiePrice= $CsData['fsetrgjiegoucjprice'];
    	$fjijiaPrice = $CsData['fsetrgjijiacjprice'];
    	$fzhuangshiPrice = $CsData['fsetrgzhuangshicjprice'];
    	$fsetzhaunlifeibl = $CsData['fsetzhaunlifeibl'];
    	$FSetCZBQPrice  = $CsData['fsetczbqprice'];
    	//专利费
    	$ZlData = SqlServerUtil::execToSql($this->SqlServer, "select * from gz_Yzhuanlif " );
    	//排放检测费
    	$pfjjData = SqlServerUtil::execToSql($this->SqlServer, "select *  from gz_Ypfceshif " );
    	
    	//税率
    	$ww_113 = 1+$fax ;
    	//委外
    	$ww_103 = $CsData['fsetweiwaif'] ;    	$ww_10000 = $CsData['fsetprodfy'] ;
    	$ww_10 = $CsData['fsetprodgzftts'] ;   	$ww_5 = $CsData['fsetprodxhdjftts'] ;
    	//图纸送审
    	$ww_106 = $CsData['fsettuzhiss'] ;
    	//运保费
    	$ww_109 = $CsData['fsetyunbaof'] ;
    	//财务
    	$ww_005 = $CsData['fsetsfcwglfy'] ;
    	$ww_005gl = $CsData['fsetglfy'] ;
    	//船检费CCS
    	$cjf_106 = $CsData['fsetchuanjianccs'] ;
    	//海外测试调试费
    	$hwtsf = empty($CsData['fsethaiwaitsf'])? 0: $CsData['fsethaiwaitsf'] ;
    	//改造费
    	$gzf = empty($CsData['fsetgaizaof'])? 0: $CsData['fsetgaizaof'] ;
    	//设置置甲醇机管理费用 (正式报价)
    	$jcj_005gl = $CsData['fsetjcjglfy'] ;
    	//设置甲醇机税费及财务费用比例
    	$jcj_005 = $CsData['fsetjcjsfcwglfy'] ;
    	//增加甲醇机的利润率
    	$jcj_005lv = $CsData['fsetjcjlv'] ;
    	//船级社设置 FSetChuanjisheBase
    	$cjsBase  = explode( ',' , $CsData['fsetchuanjishebase'] );
    	// 图纸送审
    	$ftuzhissStr = ' 0 as ftuzhiss, ';
    	if($cjsBase){
    		$ftuzhissStr = '';
    		$ftuzhissStr .=' case ' ;
    		foreach ($cjsBase as $cjs)
    		{
    			if( $cjs == 'DNV'){
    				$ftuzhissStr .= " when v1.fchuanjishe = '{$cjs}'  then Round(isnull(u1.ftuzhissDNVGL,0)*{$ww_113}/v1.fqty ,2) " ;
    			}else{
    				$ftuzhissStr .= " when v1.fchuanjishe = '{$cjs}'  then Round(isnull(u1.ftuzhiss{$cjs},0)*{$ww_113}/v1.fqty ,2) " ;
    			}
    		}
    		$ftuzhissStr .=' else 0 END as ftuzhiss, ';
    	}
    	
    	//船检费
    	$cjfStr = ' 0 as fchuanjianf , ';
    	if($cjsBase){
    		$cjfStr = '';
    		$cjfStr .=' case ' ;
    		foreach ($cjsBase as $cjs)
    		{
    			if( in_array( $cjs , ['CCS','ABS','LR','BV','DNV','NK' ] )){
    				if( $cjs == 'DNV'){
    					$cjfStr .= " WHEN cjfDNV.fchuanjishe = v1.fchuanjishe and cjfDNV.fchuanjishe = '{$cjs}' THEN  Round(cjfDNV.fchanjianfeiDNV *{$ww_113},2) " ;
    				}elseif($cjs == 'CCS'){
    					$cjfStr .= " WHEN cjf.ftype = v1.fchuanjishe and cjf.ftype ='{$cjs}' THEN  Round(cjf.fallamount/{$cjf_106} *{$ww_113},2)" ;
    				}else{
    					$cjfStr .= " WHEN cjf.ftype = v1.fchuanjishe and cjf.ftype ='{$cjs}'  THEN  Round(cjf.fallamount *{$ww_113},2) ";
    				}
    				
    			}else{
    				$cjfStr .= " WHEN cjfqt.ftype = v1.fchuanjishe and cjfqt.ftype ='{$cjs}'  THEN  Round(cjfqt.fallamount *{$ww_113},2) ";
    			}
    		}
    		$cjfStr .=' else 0 END as fchuanjianf, ';
    	}
    	
      
    	//签订合同 创建子流水号 正式报价
    	$sql ="  select v1.fbillno,v1.fmodel ,v1.fsjpower,v1.fhtpower,v1.fcxpower, v1.fqty,v1.fzlyhAmount, v1.fmarketprice,0 as fisqr,
    	v1.fzengsong,0 as fyongjin ,v1.fisyongjinbl,v1.fchuanjishe,v1.fisjingneijingwai,v1.fyongjinbl,v1.fyongjinjine,
    	v1.fyjdate,  zl.fsetzhaunlifeibl,zl.ffax as ffaxzl ,zl.fPatentfee as fzlsfbiaozhun,zl.FExchangeRate as fzlhuilv,
    	v1.fzhibaoqi,  v1.fisEGR,v1.fisSCR,v1.fisryrq,v1.fbillnoEntry,
		v1.fcustomer ,v1.fcustomerName ,v1.fmodelNO  ,v1.fjsxyNO, 
    	CASE  WHEN v1.fishwtsf = '是' THEN {$hwtsf}  else 0 End as fhaiwaitsf,  v1.fishwtsf,
    	u1.ffuliaopakeage,	u1.fbrand,u1.funit  ,  u1.fzjWeight  as ftonnage ,
    	(u1.fhanjiegs + u1.fjijiags + u1.fzhuangshigs )  as fworkhour , u1.fSCRgs as fworkhourScr , u1.fEGRgs as  fworkhourEgr ,
    	Round(isnull( cgcb.fallAmount, 0 )* {$ww_113},2)  as  ftaxSinglezjcl,
    	Round(isnull( cgcb.fallAmount, 0 ) ,2)  as  fnotaxsinglezjcl,
    	0 as fPatentfee,
    	isnull(jzcb.fallAmount,0) as fjiazhangcb ,
    	isnull(jzcbjs.fallAmount,0) as fjiazhangcbJS ,
    	isnull(jzcbcg.fallAmount,0) as fjiazhangcbCG ,
    	isnull(jzcbqt.fallAmount,0) as fjiazhangcbQT ,
    	
    	{$cjfStr} 
    	
    	Round((yq.fnoranyou*yq.fprice + yq.fnoranqi *yq.fgasPrice+ yq.fnoqigang*yq.fCylinderoilPrice),2)  as fNooneyouqifee,
    	Round(isnull(yq.fAllamount,0)*{$ww_113},2) as fyouqifee,
    	Round(isnull(pfcs.fallAmount,0)* {$ww_113}/v1.fqty ,2) as  femissionfee,
    	Round(isnull(tz.fallAmount,0)* {$ww_113}/5,2)  as fDrawingfee,
    	
    	Round(isnull(zlcb.fallAmount,0) ,2) as fqualityCost,
    	Round((isnull(prod.fweiwaiAmount,0)*{$ww_10000}/{$ww_103})* $ww_113 ,2) as fweiwaifee,
    	
    	round(((prod.fhanjiegz +prod.fjijiagz +prod.fzhuangshigz +prod.fshichegz)/{$ww_10} +prod.ffayungzzj)*{$ww_10000},2)  as fworkwhole,
    	round(((prod.fhanjiegz +prod.fjijiagz +prod.fzhuangshigz +prod.fshichegz)/{$ww_10} +prod.ffayungzfd)*{$ww_10000},2)  as fworkparted,
    	Round(isnull(prod.fxjxtsdaoju,0)*{$ww_10000}/{$ww_5} ,2)  as fcutter ,
    	
    	Round(isnull(fjhj.fallamount ,0)*{$ww_113},2) as fweldWorkfc ,
    	Round(isnull(fjjj.fallamount ,0) ,2) as fmachineWorkfc,
    	Round(isnull(fjzs.fallamount ,0)*{$ww_113},2) as  ftestWorkfc,
    	0 as ffucaitotal,
    	
    	Round(isnull(sd.fjgcjDWAmount,0) + isnull(sd.fhanjiecj,0) ,2) as  fweldWorksd ,
    	Round(isnull(sd.fjijiacj,0),2)  as  fmachineWorksd ,
    	Round(isnull(sd.fzhuangshicj,0),2)  as ftestWorksd ,
    	0  as fsdTotal,
    	
    	{$ftuzhissStr} 
    	isnull( CONVERT(DECIMAL(28,2), u1.fniuzhenRMB), 0 ) AS fniuzhenjisuanfee,
    	Round((isnull(convert(DECIMAL(28,2) ,v1.fyunbaof),0) /{$ww_109}*{$ww_113}),2) AS fyunfei,
    	
    	isnull(shts.fallAmount,0) as fsaleCost ,
    	Round(u1.fhanjiegs * u1.fhanjiePrice*{$ww_113},2)  as fweldRg ,
    	Round(u1.fjijiags * u1.fjijiaPrice*{$ww_113},2)  as fjjgRg ,
    	Round(u1.fzhuangshigs * u1.fzhuangshiPrice*{$ww_113},2) as fzhuangshiRg ,
    	0 as fzhijieRg ,
    	
    	Round(isnull(zj.fcjZjAmount,0)*{$ww_113},2) as fzhejiu ,
    	icer.fallamount  as fguanlucbAmount ,
		
    	isnull(yq.fAllamount,0)  as fyouqifeeTemp,
		isnull(scr.fICERRYAmount,0) as fICERRYAmount,
		isnull(scr.fICERRQAmount,0) as fICERRQAmount,
		isnull(scr.fEcoEGRAmount,0) as fEcoEGRAmount,
		isnull(scr.fSCRAmount,0) as fSCRAmount,
		isnull(scr.fEGRAmount,0) as fEGRAmount,
		isnull(jiachun.fallamount,0) as fjiachunAmount,
		0 as fICERAmount,
    	
    	0 as fSCRCost ,
    	0  as fEGRCost ,
    	0 as fscrIncWork ,
    	0 as fscrpfcsZS,
    	0 as fegrpfcsZS,
    	zs.fgaizaof  as fgaizaof
    	
    	from
    	gz_YBaseSC_QDHT v1
    	left join gz_YBaseJS_BAOJIA u1 on v1.fmodel = u1.fmodel  and u1.fjybjbillno = v1.fbillno
    	LEFT JOIN (SELECT SUM(fallAmount ) fallAmount,fjybjbillno FROM gz_Ycaigoucbf_BAOJIA GROUP BY fjybjbillno) cgcb on cgcb.fjybjbillno = v1.fbillno
    	left join gz_YBaseProduce_BAOJIA prod on prod.fjybjbillno = v1.fbillno

    	LEFT JOIN (SELECT SUM(fallAmount ) fallAmount,fbillnoentry  FROM gz_Yjiazhangcbf_HouXu_BAOJIA GROUP BY fbillnoentry) jzcb on jzcb.fbillnoentry = v1.fbillnoentry
    	LEFT JOIN ( SELECT SUM ( fallAmount ) fallAmount, fbillnoentry  FROM gz_Yjiazhangcbf_HouXu_BAOJIA WHERE Fbm = 'JS' GROUP BY fbillnoentry ) jzcbjs ON jzcbjs.fbillnoentry = v1.fbillnoentry
    	LEFT JOIN ( SELECT SUM ( fallAmount ) fallAmount, fbillnoentry  FROM gz_Yjiazhangcbf_HouXu_BAOJIA WHERE Fbm = 'CG' GROUP BY fbillnoentry ) jzcbcg ON jzcbcg.fbillnoentry = v1.fbillnoentry
    	LEFT JOIN ( SELECT SUM ( fallAmount ) fallAmount, fbillnoentry FROM gz_Yjiazhangcbf_HouXu_BAOJIA WHERE Fbm = 'QT' GROUP BY fbillnoentry ) jzcbqt ON jzcbqt.fbillnoentry = v1.fbillnoentry
    	
    	left join gz_Yzhiliangcb_BAOJIA zlcb on zlcb.fjybjbillno = v1.fbillno
    	left join gz_Yfucaicbf_BAOJIA  fjhj on fjhj.fjybjbillno = v1.fbillno
    	left join gz_Yfucaicbfjijia_BAOJIA  fjjj on fjjj.fjybjbillno = v1.fbillno
    	left join gz_Yfucaicbfzshi_BAOJIA fjzs on fjzs.fjybjbillno = v1.fbillno
    	
    	left join gz_Yshuidianf_BAOJIA sd on sd.fjybjbillno = v1.fbillno
    	left join gz_Yshtswhcb_BAOJIA shts on shts.fjybjbillno = v1.fbillno
    	left join gz_Yzhejiuf_BAOJIA zj on zj.fjybjbillno = v1.fbillno
    	
    	left join gz_Yyouqif_BAOJIA yq on yq.fjybjbillno = v1.fbillno
    	left join gz_Yzhuanlif_QDHT zl on zl.fjybjbillno = v1.fbillno 	AND v1.fbillnoEntry = zl.fbillnoEntry
    	left join gz_Ypfceshif_BAOJIA pfcs on pfcs.fjybjbillno = v1.fbillno
    	left join gz_Ytuzhif_BAOJIA tz on tz.fjybjbillno = v1.fbillno  
    	left join gz_Ychuanjianfgd cjf on cjf.fjybjbillno = v1.fbillno
		left join gz_YchuanjianfQT cjfqt on cjfqt.fjybjbillno = v1.fbillno
    	left join gz_YchuanjianfDNV_BAOJIA cjfDNV on cjfDNV.fjybjbillno = v1.fbillno
    	
    	left join gz_YjzSCREGRHZ scr on scr.fbillno = v1.fbillno
		left join gz_YjzJiaChunQT  jiachun on jiachun.fbillno = v1.fbillno
    	left join gz_YjzICERDB_BAOJIA  icer on icer.fjybjbillno = v1.fbillno
        inner join  gz_YbaojiadanCB zs on zs.fbillno = v1.fbillno
    	
    	where 1=1 and v1.fstatus =1 {$keywordStr} {$fbrandStr}
    	and v1.fbillnoentry not in ( select fbillnoentry from gz_YbaojiadanCB_QDHT  where  FStatus =1)  order by v1.fbillno desc ";
    	//签订合同 创建子流水号 正式报价
//     	    	echo $sql;die;
    	$res = SqlServerUtil::execToSql($this->SqlServer, $sql );
    	$result =[];
//     	    	dd($res);
    	
    	if($res ){
    		$result = arraykeyToLower($res);
    		foreach ($result as $k =>&$v)
    		{
    			$fzhuanliTemp = 0 ;
    			$fhuilvTemp = 0 ;
    			$fjiachunamountTmp  = 0;
    			//专利费  --后续 
    			$v['fpatentfee'] = round(getZLBaojia($v['fbrand'],$v['fyjdate'] ,$v['fsetzhaunlifeibl'], $v['fzlsfbiaozhun'],$v['fsjpower'],$v['fzlyhamount'],$v['fzlhuilv'])*$ww_113 ,2);
    			//辅材合计
    			$v['ffucaitotal'] = $v['fweldworkfc'] + $v['fmachineworkfc'] + $v['ftestworkfc'] ;
    			//水电合计
    			$v['fsdtotal'] = $v['fweldworksd'] + $v['fmachineworksd'] + $v['ftestworksd'] ;
    			//直接人工成本
    			$v['fzhijierg'] = $v['fweldrg'] + $v['fjjgrg'] + $v['fzhuangshirg'] ;
    			//佣金
    			$v['fyongjin'] = getYongjin($v['fmarketprice'] ,$v['fisyongjinbl'], $v['fisjingneijingwai'],$v['fyongjinbl'],$v['fyongjinjine'] ) ;
    			//超期质保费
    			$v['fcbzsfzhibaof'] =round( getYueFenValue($v['fzhibaoqi'])* $FSetCZBQPrice /6 ,2)  ;
    			//成本fICERAmount  == ICER
    			$v['ficeramount'] = getIcerData($v['ficerryamount'] ,$v['ficerrqamount'] , $v['fyouqifeetemp'] ,$v['fisryrq'] ,$ww_113)  ;
    			//成本fSCRAmount  == SCR
    			$v['fscramount'] = getScrData( $v['fscramount'], $v['fyouqifeetemp'] ,$v['fisscr'] ,$ww_113 )  ;
    			//成本fEGRAmount  == EGR
    			$v['fegramount'] = getEgrData( $v['fegramount'], $v['fyouqifeetemp'] ,$v['fecoegramount'], $v['fisegr'] ,$ww_113 )  ;
    			//甲醇机
    			$fjiachunamountTmp  = getJIAChunJIData($v['fjiachunamount'] , $v['fyouqifeetemp']    ,$ww_113 ) ;
    			$v['fjiachunamount']  = ($fjiachunamountTmp - $v['fegramount'] ) <0 ? 0:$fjiachunamountTmp - $v['fegramount'] ;
//     			//fEcoEGRAmount
//     			$v['fecoegramount'] = getEcoEGRData($v['fecoegramount'] , $v['fyouqifeetemp']    ,$ww_113 ) ;
    			
    			
    			//固定部分小计   fworkparted 工装分装
    			$v['fgdbfxiaoji'] = round($v['ftaxsinglezjcl'] +$v['fyouqifee']+$v['ffucaitotal']+$v['fsdtotal']+$v['fsalecost']
    					+$v['fqualitycost']+$v['fweiwaifee']+$v['fdrawingfee']+$v['fworkwhole']+$v['fcutter']+$v['fzhijierg'] ,2)  ;
    			//     			dd($v['fgdbfxiaoji']);
    			//变动部分小计
    			$v['fbdbfxiaoji'] = round($v['fpatentfee'] +$v['fchuanjianf']+$v['fyunfei']+$v['femissionfee']+$v['ftuzhiss']  ,2) ;
    			//项目专项成本小计	fxmzxCB
    			$v['fxmzxcb'] = round($v['fjiazhangcbcg'] +$v['fjiazhangcbjs']+$v['fjiazhangcbqt'] +$v['fscramount']+$v['fegramount']
    					+$v['ficeramount']+$v['fjiachunamount']+$v['fguanlucbamount'] +$v['fhaiwaitsf']+$v['fyongjin'] +$v['fcbzsfzhibaof']
    					+$v['fscrpfcszs'] +$v['fegrpfcszs']+$v['fgaizaof']+$v['fzengsong']  ,2)  ;
    			
    			//小计  =  项目专项成本小计 + 变动部分小计  + 固定部分小计
    			$v['fxiaoji'] = round($v['fxmzxcb'] + $v['fbdbfxiaoji'] + $v['fgdbfxiaoji'],2) ;
    			
    			//判断是否是甲醇机
    			if( stripos( strtoupper($v['fmodel']) , 'LGIM' ) !== false)    {
    				// 税费及财务费用 = (小计+ 折旧费用 ) *设置置甲醇机管理费用 (正式报价) 0.05
    				$v['fcwfy'] = round(( $v['fxiaoji'] +$v['fzhejiu']) * $jcj_005 ,2);
    				// 管理费用
    				$v['fglfy'] =  round(($v['fxiaoji'] +$v['fzhejiu'] + $v['fcwfy'] )* $jcj_005gl ,2) ;
    				// 变动成本小计 =  小计 + 税费及财务费用   + 管理费用
    				$v['fbdcb'] = $v['fxiaoji'] + $v['fzhejiu'] + $v['fcwfy'] + $v['fglfy'] ;
    				// 总成本费用
    				$v['fzcbfy'] =   round( $v['fbdcb'] * $jcj_005lv ,2) ;
    				
    			}else{	
    				// 税费及财务费用 = 小计 *0.05
    				$v['fcwfy'] = round($v['fxiaoji']  * $ww_005 ,2);
    				// 管理费用
    				$v['fglfy'] =  round(($v['fxiaoji'] + $v['fcwfy'] )* $ww_005gl ,2)  ;
    				// 变动成本小计 =  小计 + 税费及财务费用
    				$v['fbdcb'] = $v['fxiaoji'] + $v['fcwfy'] + $v['fglfy'] ;
    				// 总成本费用
    				$v['fzcbfy'] =   $v['fbdcb'] + $v['fzhejiu'] ;
    			}
    			
    			
    			unset($v['fyjdate']);
    			unset($v['fsetzhaunlifeibl']);
    			unset($v['ffaxzl']);
    			unset($v['fzlsfbiaozhun']);
    			unset($v['fzlhuilv']);
    			
    			unset($v['fisYongjinbl']);
    			unset($v['fisjingneijingwai']);
    			unset($v['fyongjinbl']);
    			unset($v['fyongjinjine']);
    			
    			unset($v['fzhibaoqi']);
    			//其他成本
    			unset($v['ficerryamount']);
    			unset($v['ficerrqamount']);
    			unset($v['fecoegramount']);
    			unset($v['fyouqifeetemp']);	
    			
    			
    			foreach ($v as $k1=>$v1)
    			{
    				if( $v[$k1] ==='.00' ||  $v[$k1] ==='.0000'  ||  $v[$k1] ==='.000' || ($v[$k1]>0 && $v[$k1]<1) ){
    					$v[$k1] = floatval($v1);
    				}
    			}
    			
    		}
    		
    	}
    	
    	
    	showMsg(200,'成功',$result );
    	
    	
    }
    
    
    
    /**
     * 签订合同 创建子流水号  -- 保存
     * @date: 2023年3月8日 上午1:27:17
     * @author: juyi
     * @param: variable
     * @return:
     */
    public function QdhtBaojiaSave(Request $request){
    	$param = $request ->get('selectedData') ;
    	$opername = $request ->opername ;
    	$FRepKey = $request ->FRepKey ;
    	
    	$db = 'gz_YbaojiadanCB_QDHT';
    	if(empty($param)){
    		showMsg(400,'保存数据不能为空');
    	}
    	$insertRecords = $param ;
    	$data=[];
    	//字符串
    	$fbillno =join("','", array_column($insertRecords, 'fbillnoentry'));
    	$fbillnoStr = "'".$fbillno ."'";
    	$delete = sqlsrv_query($this->SqlServer, "delete from {$db} where  fbillnoentry in ({$fbillnoStr}) ");
    	//
    	$getVexTableColumnData = $this->getVexTableColumn('30011') ;
    	foreach ($insertRecords as $k =>&$v)
    	{
    		unset($v['fcustomer']);
    		unset($v['fcustomername']);
    		unset($v['fmodelno']);
    		unset($v['fjsxyno']);  
    		foreach ($getVexTableColumnData as $kc=>$vc)
    		{
    			if( ( empty($v[$vc['frepfld']]) || $v[$vc['frepfld']] =='.00' ) && $vc['freptype'] == 131 ){
    				$v[$vc['frepfld']] = 0;
    			}
    			if( empty($v[$vc['frepfld']])  && ($vc['freptype'] == 202 || $vc['freptype'] == 200 ) ){
    				$v[$vc['frepfld']] = '';
    			}
    			
    			if(!in_array($vc['frepfld'],['fcustomer','fcustomername','fmodelno','fjsxyno'])   ){
    				$data[$k][$vc['frepfld']] = $v[$vc['frepfld']] ;
    			}
    		
    			$data[$k]['fcreatetime'] =  getCurrentTime() ;
    			
    		}
    	}
    	
//     	dd($data);
    	if(count($data)>400){
    		$each=400;
    		$total =count($data); //数据总数
    		$step=ceil($total/$each); //insert执行总次数
    		$j = 1;
    		$s = $step;
    		foreach ($data as $k=>$v)
    		{
    			$arr0=[];$Tmp0 =[];
    			if($j > $step) break;
    			$arr0 = array_slice($data, ($step - $s) * $each, $each);     // 每次取500条
    			$qkid =SqlServerUtil::sqlsrvAllTosql($this->SqlServer, $db ,$arr0);
    			$j++;
    			$s--;
    		}
    		
    	}else{
    		//( $db ,$data );
    		$qkid =SqlServerUtil::sqlsrvAllTosql($this->SqlServer, $db ,$data);
    		$this->writeLog(getMkName($FRepKey),'删除' , $FRepKey , $data ,$opername);
    	}
    	
    	showMsg(200,'保存成功');
    	
    	
    }
    
    
    /**
    * 加账--- 加载数据  34004  -- 加账正式报价
    * @date: 2023年3月10日 下午2:02:21
    * @author: juyi
    */
    function JZbaojiadan(Request $request){
    	$CsData =  $this->getSystemProfile(['FSetSFCWGLFY' , 'FSetGLFY','FSetGaiZaoF' ]);
    	$ww_005 = $CsData['fsetsfcwglfy'];
    	$ww_005gl = $CsData['fsetglfy'] ;
    	$gzf = empty($CsData['fsetgaizaof'])? 0: $CsData['fsetgaizaof'] ;
    	
    	$keywordStr="";
    	if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
    		$keyword =  $request->keyword ;
    		$keywordTmp = explode(',',$keyword);
    		if(count($keywordTmp)>1){
    			$tmp34004 = '';
    			foreach ($keywordTmp as $v)
    			{
    				$tmp34004 .= " or charindex('{$v}',v1.Fmodel)>0 or charindex('{$v}',v1.Fbillno)>0 or charindex('{$v}',v1.fbillnoentry )>0" ;
    			}
    			$keywordStr=' and ( '.trim($tmp34004 ,' or') .")";
    		}else{
    			$keywordStr=" and ( charindex('{$keyword}',v1.Fmodel)>0 or charindex('{$keyword}',v1.Fbillno)>0 or charindex('{$keyword}',v1.Fbillnoentry)>0   )";
    		}
    	}
    	$fbrandStr="";
    	if ($request->has('fbrand') and $request->fbrand != '' and !empty($request->fbrand)) {
    		$fbrand =  $request->fbrand ;
    		$fbrandStr=" and u1.fbrand = '{$fbrand}'  ";
    	}
    	//LEFT JOIN ( SELECT SUM ( fallAmount ) fallAmount, fjybjbillno FROM gz_Yjiazhangcbf_BAOJIA WHERE Fbm = 'QT' GROUP BY fjybjbillno ) jzcbqt ON jzcbqt.fjybjbillno = v1.fbillno
    	//加账 -  正式报价
    	$sql ="  select v1.fbillno,v1.fbillnoEntry,v1.fmodel ,v1.fsjpower,v1.fhtpower,v1.fcxpower, v1.fqty, 0 as fisqr,
		 u1.ftonnage,  isnull(jzcb.fallAmount,0) as fjiazhangcb,  isnull(jzcbjs.fallAmount,0) as fjiazhangcbJS,  
		 v1.fcustomer ,v1.fcustomerName ,v1.fmodelNO  ,v1.fjsxyNO,
		isnull(jzcbcg.fallAmount ,0) as fjiazhangcbCG,
 			isnull(jzcbqt.fallAmount,0) as fjiazhangcbQT,
        {$gzf} as fgaizaof
    	from 
    	gz_YBaseSC_HXJZ v1
    	left join gz_YbaojiadanCB u1 on u1.fbillno = v1.fbillno and u1.fstatus=1 
    	LEFT JOIN (SELECT SUM(fallAmount ) fallAmount,fbillnoentry FROM gz_Yjiazhangcbf_HXJZ_BAOJIA GROUP BY fbillnoentry) jzcb on jzcb.fbillnoentry = v1.fbillnoentry
    	LEFT JOIN ( SELECT SUM ( fallAmount ) fallAmount, fbillnoentry FROM gz_Yjiazhangcbf_HXJZ_BAOJIA WHERE 1=1  and ( Fbm ='JS') GROUP BY fbillnoentry ) jzcbjs ON jzcbjs.fbillnoentry = v1.fbillnoentry  
		LEFT JOIN ( SELECT SUM ( fallAmount ) fallAmount, fbillnoentry FROM gz_Yjiazhangcbf_HXJZ_BAOJIA WHERE 1=1  and ( Fbm ='CG') GROUP BY fbillnoentry ) jzcbcg ON jzcbcg.fbillnoentry = v1.fbillnoentry
    	LEFT JOIN ( SELECT SUM ( fallAmount ) fallAmount, fbillnoentry FROM gz_Yjiazhangcbf_HXJZ_BAOJIA WHERE 1=1  and ( Fbm ='QT') GROUP BY fbillnoentry ) jzcbqt ON jzcbqt.fbillnoentry = v1.fbillnoentry
		
		where 1=1 and v1.fstatus =1 and v1.fisqr>=3   {$keywordStr} {$fbrandStr}
    	and v1.fbillnoentry not in ( select fbillnoentry from gz_YbaojiadanCB_HXJZ  where  FStatus =1)  order by v1.fbillno desc ";
    	//签订合同 创建子流水号 正式报价
//     	 echo $sql;die;
    	$res = SqlServerUtil::execToSql($this->SqlServer, $sql );
    	$result =[];
    	if($res ){
    		$result = arraykeyToLower($res);
    		foreach ($result as $k =>&$v)
    		{
    		    $v['fjiazhangcb'] = $v['fgaizaof'] + $v['fjiazhangcb'] ; 
    			//增值税附加税及财务费用	fcwfy
    			$v['fcwfy'] = round($v['fjiazhangcb']  * $ww_005 ,2); 
    			//管理费用	fglfy
    			$v['fglfy'] =  round((  $v['fcwfy'] + $v['fjiazhangcb'] )* $ww_005gl ,2); 
    			//变动成本小计	fbdcb
    			$v['fbdcb'] =  round(( $v['fjiazhangcb']+  $v['fcwfy']+ $v['fglfy']  ) ,2); 
    			
    			foreach ($v as $k1=>$v1)
    			{
    				if( $v[$k1] ==='.00' ||  $v[$k1] ==='.0000'  ||  $v[$k1] ==='.000' || ($v[$k1]>0 && $v[$k1]<1) ){
    					$v[$k1] = floatval($v1);
    				}
    			}
    			
    		}
    		
    	}
    	showMsg(200,'成功', $result) ;
    	
    }
    
    
    
    /**
    * 加账 --保存
    * @date: 2023年3月10日 下午2:04:12
    * @author: juyi
    */
    public function JZBaojiaSave(Request $request){
    	$param = $request ->get('selectedData') ;
    	$opername = $request ->opername ;
    	$FRepKey = $request ->FRepKey ;
    	
    	$db = 'gz_YbaojiadanCB_HXJZ';
    	if(empty($param)){
    		showMsg(400,'保存数据不能为空');
    	}
    	
    	$data = $param ;
    	
    	//字符串
    	$fbillno =join("','", array_column($data, 'fbillnoentry'));
    	$fbillnoStr = "'".$fbillno ."'";
    	
    	$delete = sqlsrv_query($this->SqlServer, "delete from {$db} where  fbillnoentry in ({$fbillnoStr}) ");
    	
    	//处理不要数据
    	foreach ($data as $kv=>&$vv)
    	{
    		unset($vv['fcustomer']);
    		unset($vv['fcustomername']);
    		unset($vv['fmodelno']);
    		unset($vv['fjsxyno']); 
    	}
    	
    	if(count($data)>400){
    		$each=400;
    		$total =count($data); //数据总数
    		$step=ceil($total/$each); //insert执行总次数
    		$j = 1;
    		$s = $step;
    		foreach ($data as $k=>$v)
    		{
    			$arr0=[];$Tmp0 =[];
    			if($j > $step) break;
    			$arr0 = array_slice($data, ($step - $s) * $each, $each);     // 每次取500条
    			$qkid =SqlServerUtil::sqlsrvAllTosql($this->SqlServer, $db ,$arr0);
    			$j++;
    			$s--;
    		}
    		
    	}else{
    		$qkid =SqlServerUtil::sqlsrvAllTosql($this->SqlServer, $db ,$data);
    		$this->writeLog(getMkName($FRepKey),'删除' , $FRepKey , $data ,$opername);
    	}
    	showMsg(200,'保存成功');
    }
    
    
    /**
    * 加账 报价 明细 -- 加账报价 管理
    * @date: 2023年3月10日 下午2:16:09
    * @author: juyi
    */
    function JZBaojiaMX(request $request){
    	$FRepKey = $request->get('FRepKey');
    	$opername = $request->get('opername');
    	$fbrand = $request->get('fbrand');
    	$fmodel = $request->get('fmodel');
    	//经营报价
    	$fbillnoentry = $request->get('fbillnoentry');
    	$zsbaojiaval = $request->get('zsbaojiaval')??0;
    	//
    	$fdanweibumen = $request->get('fdanweibumen');
    	$data = $request->get('data');
    	
    	$fkeywordStr  = "" ;
    	if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
    		$keyword = $request->keyword  ;
    		$fkeywordStr=" and ( charindex('{$keyword}',u1.fname)>0 or charindex('{$keyword}',u1.fcode)>0   )" ;
    	}
    	
    	$bumenStr = "";
    	if($fdanweibumen  == 1){
    		//采购部
    		$bumenName ="采购";
    		$bumenStr=" and ( charindex('{$bumenName}',u1.fdanweibumen)>0   )" ;
    		
    	}elseif($fdanweibumen  == 2){
    		//技术中心
    		$bumenName ="技术";
    		$bumenStr=" and ( charindex('{$bumenName}', u1.fdanweibumen)>0   )" ;
    	}elseif($fdanweibumen  == 3){
    		//其他部门    =  售后服务部、生产管理部  ， 质量管理部
    		$bumenName ="售后";
    		$bumenName1 ="生产";
    		$bumenName2 ="质量";
    		$bumenName3 ="其他";
    		$bumenStr=" and ( charindex('{$bumenName}',u1.fdanweibumen)>0  or charindex('{$bumenName1}',
    		u1.fdanweibumen)>0 or charindex('{$bumenName2}',u1.fdanweibumen)>0 or charindex('{$bumenName3}',u1.fdanweibumen)>0 )" ;
    	}
    	$baseSql ="";
    	if($zsbaojiaval == 0){
	    	if($FRepKey == '34001'){
	    		$baseSql ="select row_number() OVER(ORDER BY v1.fcode  )   as N'序号',  u1.fbrand as  N'品牌',v1.fcode as  N'代码',v1.fprodno as  N'机型',u1.fname as  N'名称'
				,v1.fywqty as  N'数量',v1.fnote  N'备注'
	    						from gz_Yjiazhangcbf_HXJZ v1   inner join gz_Yjiazhangcbfset u1  on v1.fcode = u1.fcode
	    						where 1=1 and v1.fbillnoEntry = '{$fbillnoentry}' {$fkeywordStr}  " ; 
	    		$res = SqlServerUtil::execTosqlOKTO($this->SqlServer,  $baseSql);
	    		$result =[];
	    		if($res){
	    			$result = arraykeyToLower($res);
	    			foreach ($result as $k1=>&$v1)
	    			{
	    				foreach ($v1 as $k2=>$v2)
	    				{
	    					if( $v1[$k2] ==='.00' || $v1[$k2]  ==='.0000'  || $v1[$k2]  ==='.000' || $v1[$k2]  ==='.000000' || ($v1[$k2]>0 && $v1[$k2]<1) ){
	    						$v1[$k2] = floatval($v2);
	    					}
	    				}
	    			}
	    		}
	    		showMsg(0,'成功' , $result) ;
	    		
	    		
	    	}elseif($FRepKey == '34002' || $FRepKey == '34003'){
	    		$bm = 'JS' ;
	    		$bmName ='技术中心';
	    		if( $FRepKey == '34003'){
	    			$bm = 'CG' ;
	    			$bmName ='采购部';
	    		}
	    		// $keywordStr  
	    		$sqljz ="select  row_number() OVER(ORDER BY v1.fcode  )   as N'序号',  u1.fbrand as N'品牌',v1.fcode as N'代码',v1.fprodno as N'机型',u1.fdanweibumen as '部门',
	    		u1.fname as N'名称',u1.fzjQty as N'单位',v1.fywqty as N'数量'  ,
	    		case when u1.fdanweibumen  = '{$bmName}' then t1.fallAmount else 0 end as N'最新单价',
				case when u1.fdanweibumen  = '{$bmName}' then t2.fallAmount else 0 end as N'本次确认的金额',
				case when u1.fdanweibumen  = '{$bmName}' then t2.foriamount else 0 end as N'本次确认的单价',
				v1.fnote  N'备注'
	    				from gz_Yjiazhangcbf_HXJZ v1  left join gz_YjiazhangcbfSet u1 on u1.fcode =  v1.fcode
	    				left join gz_YjiazhangcbfMX  t1 on t1.fcode = v1.fcode  and t1.fprodno = v1.fprodno
						left join gz_Yjiazhangcbf_HXJZ_BAOJIA  t2 on t2.fcode = v1.fcode  and t2.fjybjbillno = v1.fbillno  and  t2.Fbm ='{$bm}'  and t2.fbillnoentry = v1.fbillnoentry 	
	    				where 1=1 and v1.fbillnoEntry = '{$fbillnoentry}' {$bumenStr} {$fkeywordStr}  ";
	    		$res = SqlServerUtil::execTosqlOKTO($this->SqlServer,  $sqljz);
	    		$result =[];
	    		if(  $FRepKey == '34003'){
	    			$fhtpower = $data['fhtpower'];
	    			$SCRCG  = SqlServerUtil::execToSql($this->SqlServer, "SELECT fpowerkw,hpscrl,hpscrh,lpscrl,lpscrh  FROM gz_YSCRSet  " );
	    		}
	    		
	    		if($res){
	    			$result = arraykeyToLower($res);
	    			foreach ($result as $k1=>&$v1)
	    			{
	    				if( $FRepKey == '34003' && stripos( $v1['名称'] , 'PSCR' ) !== false){
	    					if(substr(trim($v1['名称']),1,4) == 'PSCR') {
	    						$v1['最新单价'] = getSCRVal($SCRCG ,$fhtpower , $v1['代码'] );
	    					}
	    				}
	    				
	    				foreach ($v1 as $k2=>$v2)
	    				{
	    					if( $v1[$k2] ==='.00' || $v1[$k2]  ==='.0000'  || $v1[$k2]  ==='.000' || $v1[$k2]  ==='.000000' || ($v1[$k2]>0 && $v1[$k2]<1) ){
	    						$v1[$k2] = floatval($v2);
	    					}
	    				}
	    			}
	    		}
	    		showMsg(0,'成功' , $result) ;
	    		
	    	}elseif( $FRepKey == '34005' ){
	    		//加账财务 case when u1.fdanweibumen  ='技术中心' or u1.fdanweibumen  = '采购部' then 0  else
	    		$sqljz ="  select row_number() OVER(ORDER BY v1.fcode  )   as N'序号',   u1.fbrand as N'品牌',v1.fcode as N'代码',v1.fprodno as N'机型',u1.fdanweibumen as '部门',
	    		u1.fname as N'名称',u1.fzjQty as N'单位',v1.fywqty as N'数量'  ,
	    		t1.fallAmount as N'最新单价',	t2.fallAmount  as N'本次确认的金额', t2.foriamount  as N'本次确认的单价',v1.fnote  N'备注'
				from gz_Yjiazhangcbf_HXJZ v1  left join gz_YjiazhangcbfSet u1 on u1.fcode =  v1.fcode
	    		left join gz_YjiazhangcbfMX  t1 on t1.fcode = v1.fcode  and t1.fprodno = v1.fprodno
				left join gz_Yjiazhangcbf_HXJZ_BAOJIA  t2 on t2.fcode = v1.fcode  and t2.fjybjbillno = v1.fbillno    and t2.fbillnoentry = v1.fbillnoentry 	
	    		where 1=1 and v1.fbillnoEntry = '{$fbillnoentry}' {$bumenStr} {$fkeywordStr}  ";
	    		 // echo $sqljz;die;
	    		$res = SqlServerUtil::execTosqlOKTO($this->SqlServer,  $sqljz);
	    		$result =[];
	    		$fhtpower = $data['fhtpower'];
	    		$SCRCG  = SqlServerUtil::execToSql($this->SqlServer, "SELECT fpowerkw,hpscrl,hpscrh,lpscrl,lpscrh  FROM gz_YSCRSet  " );
	    		
	    		if($res){
	    			$result = arraykeyToLower($res);
	    			foreach ($result as $k1=>&$v1)
	    			{
	    				foreach ($v1 as $k2=>$v2)
	    				{
	    					if( stripos( $v1['名称'] , 'PSCR' ) !== false){
	    						if(substr(trim( $v1['名称']),1,4) == 'PSCR') {
	    							$v1['最新单价'] = getSCRVal($SCRCG ,$fhtpower , $v1['代码'] );
	    						}
	    					}
	    					
	    					if( $v1[$k2] ==='.00' || $v1[$k2]  ==='.0000'  || $v1[$k2]  ==='.000' || $v1[$k2]  ==='.000000' || ($v1[$k2]>0 && $v1[$k2]<1) ){
	    						$v1[$k2] = floatval($v2);
	    					}
	    				}
	    			}
	    		}
	    		showMsg(0,'成功' , $result) ;
	    	}
    	}else{
    		//$zsbaojiaval==1 调正式报价 ==  加账
    		if($FRepKey == '34002' || $FRepKey == '34003' ||  $FRepKey == '34005'){
    			$bm = 'JS' ;
    			$bmName ='技术';
    			if( $FRepKey == '34003'){
    				$bm = 'CG' ;
    				$bmName ='采购';
    			}
    			if( $FRepKey == '34005'){
    				$bm = 'QT' ;
    				$bmName ='其他';
    			}
    			$sqljz ="select v1.fbrand as  N'品牌',v1.fcode as  N'代码',v1.fprodno as  N'机型'
				,v1.fname as  N'名称',
    			v1.fywqty as  N'数量' ,v1.foriamount as '单价',v1.fallAmount as '金额'
    			from gz_Yjiazhangcbf_HXJZ_BAOJIA  v1  where 1=1 and v1.fbillnoEntry = '{$fbillnoentry}'  
				and v1.fbm ='{$bm}'";
    			$res = SqlServerUtil::execTosqlOKTO($this->SqlServer,  $sqljz);
    			//     		dd($res);
    			$result =[];
    			if($res){
    				$result = arraykeyToLower($res);
    				foreach ($result as $k1=>&$v1)
    				{
    					foreach ($v1 as $k2=>$v2)
    					{
    						if( $v1[$k2] ==='.00' || $v1[$k2]  ==='.0000'  || $v1[$k2]  ==='.000' || $v1[$k2]  ==='.000000' || ($v1[$k2]>0 && $v1[$k2]<1) ){
    							$v1[$k2] = floatval($v2);
    						}
    						// fnbfhyx
    					}
    				}
    			}
    			showMsg(0,'成功' , $result) ;
    			
    		} else{
    			//正式报价加账 -- 合计
    			$sqljz ="select v1.fbrand as  N'品牌',v1.fcode as  N'代码',v1.fprodno as  N'机型',v1.fname as  N'名称',
    			v1.fywqty as  N'数量' ,v1.foriamount as '单价',v1.fallAmount as '金额'
    			from gz_Yjiazhangcbf_HXJZ_BAOJIA  v1  where 1=1 and v1.fbillnoEntry = '{$fbillnoentry}'  ";
    			$res = SqlServerUtil::execTosqlOKTO($this->SqlServer,  $sqljz);
//     			echo $sqljz;die;
//     			dd($res);
    			$result =[];
    			if($res){
    				$result = arraykeyToLower($res);
    				foreach ($result as $k1=>&$v1)
    				{
    					foreach ($v1 as $k2=>$v2)
    					{
    						if( $v1[$k2] ==='.00' || $v1[$k2]  ==='.0000'  || $v1[$k2]  ==='.000' || $v1[$k2]  ==='.000000' || ($v1[$k2]>0 && $v1[$k2]<1) ){
    							$v1[$k2] = floatval($v2);
    						}
    						// fnbfhyx
    					}
    				}
    			}
    			showMsg(0,'成功' , $result) ;
    		}
    		
    	}
    	
    }
    
    /**
    * 各个部门明细
    * @date: 2023年3月11日 上午10:19:57
    * @author: juyi
    */
    function FBMluruMx(request $request){
    	$FRepKey = $request->get('FRepKey');
    	$opername = $request->get('opername');
    	$fmodel = $request->get('fmodel');
    	
    	$page= $request ->get('page');
    	if(!isset($page)) $page =1;
    	$limit= $request ->get('limit');
    	if(!isset($limit)) $limit =20;
    	$pages = ($page-1)* $limit;
    	
    	$row= $request ->get('row');
    	
    	$result = [];
    	if(!in_array($FRepKey,['26010', '26015','26019', '26004',]) ){
    		if(empty($fmodel)){
    			showMsg(400,'该机型不能为空');
    		}
    	}
    	
    	$db = columnBiao($FRepKey);
    	$dbMX = $db.'MX';
    	$param =[];
    	if(in_array($FRepKey,['26002'])){
    		$sqlMX="select top $limit * from ( select row_number() over(order by v1.fid desc ) as rownumber
    		,v1.* ,t2.fbrand,t2.fmoli  as fmali,t2.fzhuansu,t2.fpower ,t2.funit
    		from {$dbMX}  v1
    		left join  gz_YBaseJS t2 on  t2.fmodel = v1.fmodel
    		where 1=1  and v1.fmodel = '{$fmodel}'  ) temp_row where rownumber>(($page-1)*$limit)  ";
    	}elseif(in_array($FRepKey,['25002']) ){
    		$sqlMX="select top $limit * from ( select row_number() over(order by v1.fid desc ) as rownumber,v1.fid,v1.fchuanjishe,v1.FExchangeRate,v1.fzjjianyanf,
    		v1.fzjjianyanfRMB,v1.fnoxpaifangf,v1.fnoxpaifangfRMB,v1.fzhengshuf,v1.fmodel,
    		v1.fzhengshufRMB,v1.flvtuf,v1.flvtufRMB,v1.fjizuojijiafRMB,
    		v1.fzhusufRMB,v1.franyoufRMB,v1.fguolufRMB,v1.fhuosibutieRMB,
    		v1.fpaifangtestfRMB,v1.fzztaxAmount,v1.fallamount,v1.fchanjianfeiabs,
    		v1.fcreatetime,v1.FStatus,v1.checkName,t2.fbrand,t2.fmoli  as fmali,t2.fzhuansu,t2.fpower ,t2.funit
    		from  {$dbMX}    v1
    		left join  gz_YBaseJS t2 on  t2.fmodel = v1.fmodel
    		where 1=1  and v1.fmodel = '{$fmodel}'  ) temp_row where rownumber>(($page-1)*$limit)  ";
    	}elseif(in_array($FRepKey,['25003']) ){
    		$sqlMX = "select top $limit * from ( select row_number() over(order by v1.fid desc ) as rownumber
			 ,v1.fid,v1.fmodel,v1.fchuanjishe, v1.fzjjianyanf,
			 v1.fnoxpaifangf, v1.flvtuf, v1.fjizuojijiaf, v1.fzhusuf,
			 v1.fguoyejintie, v1.franyouf, v1.fguoluf, v1.fzhengshuf,
			 v1.fpaifangtestf, v1.fzztaxAmount, v1.fallamount, v1.fchanjianfeiLR,
			 v1.fcreatetime, v1.FStatus, v1.checkName ,t2.fbrand,t2.fmoli  as fmali,t2.fzhuansu,t2.fpower ,t2.funit  
			from  {$dbMX}   v1  
			left join  gz_YBaseJS t2 on  t2.fmodel = v1.fmodel 
			where 1=1 and v1.fmodel = '{$fmodel}'  ) temp_row where rownumber>(($page-1)*$limit)  ";
    		
    	}elseif(in_array($FRepKey,['25004']) ){
    		$sqlMX = "select top $limit * from ( select row_number() over(order by v1.fid desc ) as rownumber
			 ,v1.fid,v1.fmodel,v1.fchuanjishe, v1.fzjjianyanf,
			  v1.fnoxpaifangf,v1.flvtuf,v1.fjizuojijiaf,v1.fzhusuf,
			v1.franyouf,v1.fguoluf,v1.fzhengshuf,v1.fpaifangtestf,
			v1.fzztaxAmount,v1.fallamount,v1.fchanjianfeiBV,
			  v1.fcreatetime, v1.FStatus, v1.checkName ,t2.fbrand,t2.fmoli  as fmali,t2.fzhuansu,t2.fpower ,t2.funit  
			from {$dbMX}  v1  
			left join  gz_YBaseJS t2 on  t2.fmodel = v1.fmodel 
			where   1=1 and v1.fmodel = '{$fmodel}'  ) temp_row where rownumber>(($page-1)*$limit)  ";
    		
    	}elseif(in_array($FRepKey,['25005']) ){
    		$sqlMX = "select top $limit * from ( select row_number() over(order by v1.fid desc ) as rownumber
			 ,v1.fid,v1.fmodel,v1.fchuanjishe, v1.fzjjianyanf,
			  v1.fnoxpaifangf,v1.flvtuf,v1.fjizuojijiaf,v1.fzhusuf,v1.fchuchaibutie,
			v1.franyouf,v1.fguoluf,v1.fzhengshuf,v1.fpaifangtestf,
			v1.fzztaxAmount,v1.fallamount,v1.fchanjianfeiDNV,
			  v1.fcreatetime, v1.FStatus, v1.checkName ,t2.fbrand,t2.fmoli  as fmali,t2.fzhuansu,t2.fpower ,t2.funit  
			from {$dbMX}  v1  
			left join  gz_YBaseJS t2 on  t2.fmodel = v1.fmodel 
			where 1=1 and v1.fmodel = '{$fmodel}'  ) temp_row where rownumber>(($page-1)*$limit)  ";
    		
    	}elseif(in_array($FRepKey,['26010' ]) ){
    		//折旧
    		$sqlMX = "select top $limit * from ( select row_number() over(order by fid desc) as rownumber ,* from {$dbMX}
    		where 1=1 and fyear ='{$row['fyear']}' ) temp_row where rownumber>(($page-1)*$limit) ";
    	}elseif(in_array($FRepKey,[ '26004'  ]) ){
    		//专利费  
    		$sqlMX = "select top $limit * from ( select row_number() over(order by fid desc) as rownumber ,* from {$dbMX}
    		where 1=1 and fname ='{$row['fname']}' ) temp_row where rownumber>(($page-1)*$limit) ";
    	}elseif(in_array($FRepKey,[ '26019' ]) ){
    		//排放测试费 
    		$sqlMX = "select top $limit * from ( select row_number() over(order by fid desc) as rownumber ,* from {$dbMX}
    		where 1=1 and fname ='{$row['fname']}' ) temp_row where rownumber>(($page-1)*$limit) ";
    	}elseif(in_array($FRepKey,[ '26015']) ){
    		//图纸费 
    		$sqlMX = "select top $limit * from ( select row_number() over(order by fid desc) as rownumber ,* from {$dbMX}
    		where 1=1 and fname ='{$row['fname']}' and fbrand ='{$row['fbrand']}'  and fleixing ='{$row['fleixing']}' ) temp_row where rownumber>(($page-1)*$limit) ";
    	}elseif(in_array($FRepKey,[ '26028']) ){
    		$sqlMX="select top $limit * from ( select row_number() over(order by fid desc) as rownumber ,* from {$dbMX}
    		where 1=1 and fpowerkW = '{$fmodel}'  ) temp_row where rownumber>(($page-1)*$limit) ";
    	}elseif(in_array($FRepKey,[ '27010']) ){
    		//ICER数据库信息技术 
    		$sqlMX="select top $limit * from ( select row_number() over(order by fid desc) as rownumber ,* from {$dbMX}
    		where 1=1 and fEGCModel = '{$fmodel}'  and fjscg = 'JS'  ) temp_row where rownumber>(($page-1)*$limit) ";
    	}elseif(in_array($FRepKey,[ '27011']) ){
    		//ICER数据库信息采购
    		$sqlMX="select top $limit * from ( select row_number() over(order by fid desc) as rownumber ,* from {$dbMX}
    		where 1=1 and fEGCModel = '{$fmodel}'  and fjscg = 'CG' ) temp_row where rownumber>(($page-1)*$limit) ";
    	}elseif(in_array($FRepKey,[ '14002']) ){
    		$sqlMX="select top $limit * from ( select row_number() over(order by FItemID desc) as rownumber ,* from {$dbMX}
    		where 1=1 and FKey = '{$fmodel}'  ) temp_row where rownumber>(($page-1)*$limit) ";
    	}elseif(in_array($FRepKey,[ '25007']) ){
    	    $sqlMX="select top $limit * from ( select row_number() over(order by v1.FID desc) as rownumber ,v1.* ,u1.fqty as fsxqty 
            from {$dbMX} v1 
    	    left join gz_YbaseSC u1 on   u1.fbillno= v1.fjybjbillno
    	    where 1=1 and v1.fjybjbillno = '{$fmodel}'  ) temp_row where rownumber>(($page-1)*$limit) ";
    	}else{
    		$sqlMX="select top $limit * from ( select row_number() over(order by fid desc) as rownumber ,* from {$dbMX}
    		where 1=1 and fmodel = '{$fmodel}'  ) temp_row where rownumber>(($page-1)*$limit) ";
    	}
//     	$sql =" select * from {$dbMX} where 1=1 and fmodel = '{$fmodel}' order by fid desc " ;
//     	echo $sqlMX;die;
    	$result1  = SqlServerUtil::execTosqlOK($this->SqlServer, $sqlMX );
    	$result = arraykeyToLower($result1);
    	
    	$countSql ="SELECT COUNT(1) AS total FROM  {$dbMX} where 1=1 and fmodel = '{$fmodel}' ";
    	if(in_array($FRepKey,['26010' ]) ){
    		$countSql ="SELECT COUNT(1) AS total FROM  {$dbMX} where 1=1 and fyear ='{$row['fyear']}' ";
    	}
    	if(in_array($FRepKey,['26004' ]) ){
    		$countSql ="SELECT COUNT(1) AS total FROM  {$dbMX} where 1=1 and fname ='{$row['fname']}' ";
    	}
    	if(in_array($FRepKey,['26019' ]) ){
    		$countSql ="SELECT COUNT(1) AS total FROM  {$dbMX} where 1=1 and fname ='{$row['fname']}'";
    	}
    	if(in_array($FRepKey,['26015' ]) ){
    		$countSql ="SELECT COUNT(1) AS total FROM  {$dbMX} where 1=1 and fname ='{$row['fname']}' and fbrand ='{$row['fbrand']}'  and fleixing ='{$row['fleixing']}'  ";
    	}
    	
    	if(in_array($FRepKey,['27010' ]) ){
    		$countSql ="SELECT COUNT(1) AS total FROM  {$dbMX} where 1=1 and fEGCModel = '{$fmodel}'  and fjscg = 'JS'  ";
    	}
    	
    	if(in_array($FRepKey,['27011' ]) ){
    		$countSql ="SELECT COUNT(1) AS total FROM  {$dbMX} where 1=1  and fEGCModel = '{$fmodel}'  and fjscg = 'CG' ";
    	}
    	if(in_array($FRepKey,['26028' ]) ){
    		$countSql ="SELECT COUNT(1) AS total FROM  {$dbMX} where 1=1  and fpowerkW = '{$fmodel}'  ";
    	}
    	
    	if(in_array($FRepKey,['14002' ]) ){
    		$countSql ="SELECT COUNT(1) AS total FROM  {$dbMX} where 1=1  and FKey = '{$fmodel}'  ";
    	}
    	
    	$count = SqlServerUtil::execToSql($this->SqlServer, $countSql,2);
    	$total = isset($count['total'])?(!empty($count['total']) ? $count['total']:0):0;
    	$this->response['total'] = $total;
    	$this->response['size'] = 1;
    	$last_page = 0;
    	if($count && count($count)>0){
    		$last_page = !empty($total) ? ceil($total/$limit):0;
    		$this->response['size'] = $limit;
    	}
    	
    	$this->response['Data'] = $result;
    	$this->response['cur_page'] =$page;
    	$this->response['last_page'] =$last_page;
    	return response()->json($this->response);
    }
    
    /**
     * 各个部门明细 -- 报价单
     * @date: 2023年3月11日 上午10:19:57
     * @author: juyi
     */
    function FBMluruMxBAOJIA(request $request){
    	$FRepKey = $request->get('FRepKey');
    	$opername = $request->get('opername');
    	$fmodel = $request->get('fmodel');
    	
    	$page= $request ->get('page');
    	if(!isset($page)) $page =1;
    	$limit= $request ->get('limit');
    	if(!isset($limit)) $limit =20;
    	$pages = ($page-1)* $limit;
    	
    	$result = [];
    	if(empty($fmodel)){
    		showMsg(400,'该机型不能为空');
    	}
    	$db = columnBiao($FRepKey);
    	$dbMX = $db.'_BAOJIA';
    	$param =[];
    	//     	$sql =" select * from {$dbMX} where 1=1 and fmodel = '{$fmodel}' order by fid desc " ;
    	$sqlMX="select top $limit * from ( select row_number() over(order by fid desc) as rownumber ,* from {$dbMX}
    	where 1=1 and fmodel = '{$fmodel}'  ) temp_row where rownumber>(($page-1)*$limit) ";
    	$result1  = SqlServerUtil::execTosqlOK($this->SqlServer, $sqlMX );
    	$result = arraykeyToLower($result1);
    	
    	$countSql ="SELECT COUNT(1) AS total FROM  {$dbMX} where 1=1 and fmodel = '{$fmodel}' ";
    	$count = SqlServerUtil::execToSql($this->SqlServer, $countSql,2);
    	$total = isset($count['total'])?(!empty($count['total']) ? $count['total']:0):0;
    	$this->response['total'] = $total;
    	$this->response['size'] = 1;
    	$last_page = 0;
    	if($count && count($count)>0){
    		$last_page = !empty($total) ? ceil($total/$limit):0;
    		$this->response['size'] = $limit;
    	}
    	
    	$this->response['Data'] = $result;
    	$this->response['cur_page'] =$page;
    	$this->response['last_page'] =$last_page;
    	return response()->json($this->response);
    }
    
    
    /**
    * 正式报价 加账  -- 手动新增 
    * @date: 2023年4月9日 下午4:41:08
    * @author: juyi
    */
    public function hxGenAdd(Request $request){
    	$FRepKey= $request->get('FRepKey');
    	$db = columnBiao(34001);//表名
    	$opername  = $request->opername?$request->opername:'' ;
    	$FRepPage  = $request->FRepPage??0 ; //这里0 -- 序时薄 ，1-单据
    	 
    	$data =  $request->all() ;
    	$getVexTableColumnData = $this->getVexBillColumn($FRepKey  ) ;
    	$fisrqr =  $request->fisrqr??0 ;  //再次确认情况
    	$resMX = [];
    	 
    	$fidField ='fid';
    	// 新增 -- insertRecords,
    	$insertRecords = isset($data['insertRecords'])?$data['insertRecords'] :[];
    	
    	$updateRecords = isset( $data['updateRecords'])?$data['updateRecords'] :[];
    	
    	
    	 if(in_array($FRepKey, [ '34001','30010'] )){
    	 	if(in_array($FRepKey, [  '30010'] )){
    	 		$db = columnBiao(30010) ;
    	 	}
    		//业务需求(市场部)   14009
    		if( empty($insertRecords) &&  empty($updateRecords) ){
    			showMsg(1,'请输入必要字段（机型）' );
    		}
    		//业务
    		//判断 WINGD和 MAN
    		//业务优惠金额 不得超过 专利收费标准金额
    		if( !empty($insertRecords)){
    			//设计功率
    			//专利费
    			$ZlData = SqlServerUtil::execToSql($this->SqlServer, "select * from gz_Yzhuanlif " );
    			foreach ($insertRecords as $ks =>$vs)  {
    				$brand = SqlServerUtil::execTosql($this->SqlServer, "select fbrand,fpower  from gz_YBaseJS where fmodel ='{$vs['fmodel']}'",2 );
    				if(empty($brand)){
    					showMsg(400,'请检验机型，是否正确');
    				}
    				//常规机不能是 燃油或燃气 版
    				if( fisDFRanYou($vs['fmodel'],$vs['fisryrq'])){
    					showMsg(400,'请检验机型是否是双料机，您选择 是：'.$vs['fisryrq']);
    				}
    				//     				dd($fisrqr,$fisrqr !=0 ,$brand['fpower']  ,$vs['fsjpower'] ,$brand['fpower']  !=$vs['fsjpower'] );
    				if($fisrqr ==0){
    					if($brand['fpower']  != $vs['fsjpower'] ){
    						showMsg(14009,'请检验是否和技术中心功率保持一致！');
    					}
    				}
    				$tt = getZLValueYS($ZlData, $vs['fmodel'],$brand['fbrand']);
    				if($tt){
    					if($vs['fzlyhamount'] > $tt['fPatentfee'] ){
    						showMsg(400,'业务优惠金额 不得超过 专利收费标准金额');
    					}
    				}
    			}
    		}
    	} 
    	
    	//新增 ===
    	if(!empty($insertRecords)){
    		$insData=[];
    		foreach ($insertRecords as $k =>&$v)
    		{
    			$where= [];
    			if(isset($v['fid']) ) {
    				$where[$fidField] = $v[$fidField];
    			}
    			foreach ($getVexTableColumnData as $kc=>$vc)
    			{
    				if( ( empty($v[$vc['frepfld']]) || $v[$vc['frepfld']] =='.00' ) && $vc['freptype'] == 131 ){
    					$v[$vc['frepfld']] =0;
    				}
    				if( empty($v[$vc['frepfld']])  && ($vc['freptype'] == 202 || $vc['freptype'] == 200 ) ){
    					$v[$vc['frepfld']] = '';
    				}
    				$insData[$k][$vc['frepfld']] = $v[$vc['frepfld']] ;
    				$insData[$k]['fcreatetime'] = getCurrentTime();
    			}
    			//市场部需求 14009
    			$aaTmp =[];
    			if($FRepKey == 14009){
    				$aaTmp = explode('+', $v['fsxtaishu'])   ;
    				// fsxtaishu
    				$insData[$k]['fqty'] =  intval(array_shift( $aaTmp ))   ;
    				//生成序列号
    				if(!isset($v['fid']) ) {
    					$no = $this->getDanHao(14009);
    					$insData[$k]['fbillno'] =  $no ;
    					$insData[$k]['fbillnoEntry'] =  $no.'-JZ001' ;
    				}
    			}
    			
    		}
    		if(isset($v['fid']) ) {//修改
    			foreach ($insData as $kgen =>&$vgen)
    			{
    			   unset($vgen['jiazhangdata']);
    			   SqlServerUtil::exeupdateTosql($this->SqlServer,$db,$vgen,$where);
    			}
    		}else{
    			SqlServerUtil::sqlsrvAllTosql($this->SqlServer ,$db , $insData);
    		}
    	}
    	showMsg(0,'成功' );
    }
    
    
    /**
    *  参数 --保存 
    * @date: 2023年4月10日 上午9:13:11
    * @author: juyi
    */
    public function cenShuSave(Request $request){
    	$FRepKey= $request->get('FRepKey');
    	$db = columnBiao($FRepKey);//表名
    	$opername  = $request->opername?$request->opername:'' ;
    	$FRepPage  = $request->FRepPage??0 ; //这里0 -- 序时薄 ，1-单据
    	
    	$data =  $request->all() ;
    	//进入参数设置操作 
    	Log::info("参数设置---进入当前操作   --参数设置--URL接口地址  :" . $request->url() . '  ----参数：' . urldecode(http_build_query($request->all())) . "\r\n \r\n");
    	
    	$getVexTableColumnData = $this->getVexTableColumn($FRepKey , $FRepPage) ;
    	//判断是否在系统管理员组
    	$conSql ="SELECT  ad.username,g.fname  from gz_user_group ug
    	left join  gz_admin ad   on ug.userid = ad.id
    	left join gz_group g  on  g.id = ug.groupid
    	where g.fname = '系统管理员组'  and  ad.username ='{$opername}' ";
    	$ConData = SqlServerUtil::execToSql($this->SqlServer, $conSql  );
    	
    	if(empty($ConData))
    	{
    		$sql = "SELECT ad.username,g.fname,g.id ,ag.FAccessMask from gz_user_group ug
    		left join gz_admin ad   on ug.userid = ad.id
    		left join gz_group g  on  g.id = ug.groupid
    		left join gz_accesscontrol_group ag on ag.fuserid=ug.groupid  and FObjectID = '{$FRepKey}'
    		where ad.username = '{$opername}' ";
    		$res2 = SqlServerUtil::execTosql($this->SqlServer, $sql,2);
    		$FAccessMask = 8;
    		if($res2){
    			$FAccessMaskV = $res2['FAccessMask'];
    			if (($FAccessMaskV & $FAccessMask) != $FAccessMask) { //用户自身具备权限
    				showMsg(400,'此用户没有修改权限');
    			}
    		}else{
    			showMsg(400,'此用户没有修改权限');
    		}
    	}
    	
    	// 新增 -- insertRecords,
    	$insertRecords = isset($data['insertRecords'])?$data['insertRecords'] :[];
    	if(!empty($insertRecords)){
    		$insData=[];
    		foreach ($insertRecords as $k =>&$v)
    		{
    			foreach ($getVexTableColumnData as $kc=>$vc)
    			{
    				if( ( empty($v[$vc['frepfld']]) || $v[$vc['frepfld']] =='.00' ) && $vc['freptype'] == 131 ){
    					$v[$vc['frepfld']] =0;
    				}
    				
    				if( empty($v[$vc['frepfld']])  && ($vc['freptype'] == 202 || $vc['freptype'] == 200 ) ){
    					$v[$vc['frepfld']] = '';
    				}
    				$insData[$k][$vc['frepfld']] = $v[$vc['frepfld']] ;
    			}
    			
    			$insData['fcreatemanager'] = $opername;
    		}
    		
    		SqlServerUtil::sqlsrvAllTosql($this->SqlServer ,$db , $insData);
    		$this->writeLog(getMkName($FRepKey),'新增' , $FRepKey , $insData ,$opername );
    	}
    	
    	// 启动事务
    	if (sqlsrv_begin_transaction($this->SqlServer) === false) {
    		die(print_r(sqlsrv_errors(), true));
    	}
    	
    	// 修改 --  updateRecords,
    	$updateRecords = isset( $data['updateRecords'])?$data['updateRecords'] :[];
    	$fidField = 'fitemid';
    	
    	if(!empty($updateRecords)){
    		$incenshu = false ;
    		$insMX =  false ;
    		
    		$ingd  = false ;
    		$insabs = false ;  
    		$inszl = false ;  //专利 
    		$inssdf  = false ;  //水电费 
    		$instz = false ;  //图纸费
    		$inszs = false ;  //辅材装试
    		$inshj = false ;  // 焊接
    		$insccs = false ;  //CCS
    		$insyb  = false ;  //运保 
    		$insjj  = false ;  //机加
    		
    		$indataTmp =[];$KeyTmp =[];
    		foreach ($updateRecords as $kup=>&$vup)
    		{
    			$insData =[];
    			$where= [];
    			
    			$where[$fidField] = $vup[$fidField];
    			
    			foreach ($getVexTableColumnData as  $up)
    			{
    				if( ( empty($vup[$up['frepfld']]) || $vup[$up['frepfld']] =='.00' ) && $up['freptype'] == 131 ){
    					$vup[$up['frepfld']] =0;
    				}
    				
    				if( empty($vup[$up['frepfld']])  && ($up['freptype'] == 202 || $up['freptype'] == 200 ) ){
    					$vup[$up['frepfld']] = '';
    				}
    				
    				$insData[$up['frepfld']] = $vup[$up['frepfld']] ;
    			}
    			$KeyTmp[$kup] = $insData;
    			$KeyTmp[$kup]['fcreatemanager'] = $opername;
    			$KeyTmp[$kup]['fcreatetime'] = getCurrentTime();
    			$KeyTmp[$kup]['fcategory'] = 'IB' ;
    			
    			$indataTmp[$kup]['fdescription'] = $insData['fdescription'] ;
    			$indataTmp[$kup]['fvalue'] = $insData['fvalue'] ;
    			$indataTmp[$kup]['fexplanation'] = $insData['fexplanation'] ;
    			
    			$indataTmp[$kup]['fitemid'] = $vup[$fidField] ;
    			$indataTmp[$kup]['fcreatetime'] = getCurrentTime();
				$indataTmp[$kup]['fcreatemanager'] = $opername;
				
    			//$incenshu = SqlServerUtil::exeupdateTosql($this->SqlServer,$db,$insData,$where);
    		}
    		//判断 
    		//     			FSetHuiLv  -- 设置今日汇率 --美元
    		//     			FSetHuiLvFaLang  -- 瑞士法郎
    		//     			FSetHuiLvOyuan -- 欧元
    		//     			FSetShuiDianjgcjPrice   -- 水电费--结构车间吨位单价
    		//     			FSetFuCai550Value  -- 辅材成本 -- 550计算值（辅料）
    		//     			FSetFuCai535Value  -- 辅材成本 -- 535计算值（辅料）
    		//     			FSetFuCaiBZW535Value -- 辅材成本 -- 535计算值（包装物）
    		//     			FSetFuCaiBZW550Value -- 辅材成本 -- 550计算值（包装物）
    		//     			FSetFuCaiDWPrice - 辅材焊接
    		//     			FSetProdFY - 设置生产费用委外、消耗刀具（万元）
    		//     			FSetChuanjianCCS  - 设置船检CCS比例
    		//     			FSetYunBaoF  -- 设置运保费、运输费比例
    		//     			FSetTuZhiSS --  设置图纸送审比例、保险费
    		
    		$bbArr =[ 'FSetHuiLv','FSetHuiLvFaLang','FSetHuiLvOyuan','FSetShuiDianjgcjPrice','FSetFuCai550Value','FSetFuCai535Value',
    				'FSetFuCaiBZW535Value','FSetFuCaiBZW550Value','FSetFuCaiDWPrice','FSetProdFY','FSetChuanjianCCS','FSetYunBaoF','FSetTuZhiSS' ];
    		if($KeyTmp && count($KeyTmp)>1){
    			$aaArr = array_unique(array_column($KeyTmp,'fkey'));
    			$intersection = array_intersect($aaArr , $bbArr);
    			
    			if( $intersection && count($intersection)>1 ){
    				$Mes = ''; 
    				$MesStr =' ，请修改其中一个再保存！';
    				$Mes = getArrContent($KeyTmp,  $intersection). $MesStr; 
    				showMsg(400, $Mes);
    			}
    		}
    		//参数设置 修改
    		$this->writeLog(getMkName($FRepKey),'修改' , $FRepKey , $updateRecords ,$opername );
//     		dd($KeyTmp ,$db , $indataTmp );
    		//修改备份
    		$insMX = SqlServerUtil::sqlsrvAllTosql($this->SqlServer ,$db.'MX' , $KeyTmp);
    		
 			//修改 
    		$incenshu = SqlServerUtil::sqlsrvkqUpdateNO($this->SqlServer,$db,$indataTmp,$where);

    		//美元 更新  
    		if($insData['fkey'] == "FSetHuiLv"){
    			//1、船检费固定26024
    			$sqlcj =  " select * from gz_YchuanjianfSet where ftype ='ABS' and fzhengshuf >0 and  fnoxpfMX>0  and  fnoxpfMX>0 " ;
    			$Tmpcj1 =  SqlServerUtil::execToSql($this->SqlServer, $sqlcj ,2 );
    			$Tmpcj = arraykeyToLower($Tmpcj1) ; 
    			//船检固定参数更新
    		 	$cjdata =[]; 
    			// fhuilv -- 汇率
    		 	$cjdata['fhuilv']=  empty($insData['fvalue'])?0:$insData['fvalue'];
    			//证书费(人民币)
    		 	$cjdata['fzhengshufrmb']= $Tmpcj['fzhengshuf']* $cjdata['fhuilv'] ;
     			//过程检验(人民币)
    		 	$cjdata['fscjjrmb']= $Tmpcj['fscjj']* $cjdata['fhuilv'] ;
    		 	//确定
    		 	$cjdata['fqueding']= $cjdata['fzhengshufrmb']+  $cjdata['fscjjrmb']+ $Tmpcj['flutufrmb'] ;
    		 	$cjdata['fnoxpfmxrmb']= $Tmpcj['fnoxpfmx']* $cjdata['fhuilv'] ;
    		 	$cjdata['fnoxpfzxrmb']= $Tmpcj['fnoxpfzx']* $cjdata['fhuilv'] ;
    		 	$ingd =	SqlServerUtil::exeupdateTosql($this->SqlServer,'gz_YchuanjianfSet',$cjdata,['fid'=>$Tmpcj['fid']]);
    			
    		 	// 2、船检费ABS   25002
    		 	$sqlABS =  " select * from gz_YchuanjianfABS where 1=1 " ;
    		 	$Tmpabs1 =  SqlServerUtil::execToSql($this->SqlServer, $sqlABS   );
    		 	$Tmpabs = arraykeyToLower($Tmpabs1) ; 
//     		 	$param = [];
//     		 	$insDataABS = [] ;
    		 	$getColumnABS = $this->getVexTableColumn(25002 , $FRepPage) ;
    		 	if(!empty($Tmpabs) ){
    		 		$ABSData = [] ;
					foreach ($Tmpabs as $kup=>&$vup)
					{
						$param =[];
						$where= [];
						
						$where['fid'] = $vup['fid'];
						
						foreach ($getColumnABS as  $up)
						{
							if( ( empty($vup[$up['frepfld']]) || $vup[$up['frepfld']] =='.00' ) && $up['freptype'] == 131 ){
								$vup[$up['frepfld']] =0;
							}
							
							if( empty($vup[$up['frepfld']])  && ($up['freptype'] == 202 || $up['freptype'] == 200 ) ){
								$vup[$up['frepfld']] = '';
							}
							$param['fid'] = $vup['fid'];
			    		 	$param['fexchangerate'] = $insData['fvalue'] ;
			    		 	//整机检验费人民币
			    		 	$param['fzjjianyanfrmb'] =  round( $vup['fzjjianyanf']*$param['fexchangerate'] ,2);
			    		 	//NOX排放费人民币
			    		 	$param['fnoxpaifangfrmb'] = round($vup['fnoxpaifangf'] *$param['fexchangerate'] ,2) ;
			    		 	//证书费人民币
			    		 	$param['fzhengshufrmb'] =  round($vup['fzhengshuf'] *$param['fexchangerate'] ,2);
			    		 	//旅途时间费用人民币 
			    		 	$param['flvtufrmb'] =  round( $vup['flvtuf'] *$param['fexchangerate']*30 ,2) ;
			    		 		
			    		 	//  船检费ABS
			    		 	$param['fchanjianfeiabs']  =  $param['fzjjianyanfrmb'] + $param['fnoxpaifangfrmb'] + $param['fzhengshufrmb'] 
			    		 	+ $param['flvtufrmb'] + $vup['fzhusufrmb'] + $vup['franyoufrmb'] + $vup['fguolufrmb']+  $vup['fhuosibutiermb']   ;
							 
						}
						$ABSData[$kup] = $param ; 
					}
				$insabs = SqlServerUtil::sqlsrvkqUpdateTosql($this->SqlServer,'gz_YchuanjianfABS',$ABSData,'fid');
				}
				if( $insMX && $incenshu  && $ingd && $insabs){
					sqlsrv_commit($this->SqlServer);
					showMsg(200,'成功!');
				}else {
					sqlsrv_rollback($this->SqlServer);
					showMsg(400,'修改失败');
				}
    		 	
    		}//是否是美元
    		
    		//专利合计26004  FSetHuiLvFaLang  瑞士法郎   FSetHuiLvOyuan 欧元
    		// 图纸费  26015
    		if(in_array($insData['fkey'] , ['FSetHuiLvOyuan' ,'FSetHuiLvFaLang'] )   ){
    			$sqlZL = " SELECT * FROM  gz_Yzhuanlif ";
    			$Tmpzl1 =  SqlServerUtil::execToSql($this->SqlServer, $sqlZL   );
    			$Tmpzl = arraykeyToLower($Tmpzl1) ; 
    			// 图纸费  26015
    			$Tmptz1 =  SqlServerUtil::execToSql($this->SqlServer, " SELECT * FROM  gz_Ytuzhif "   );
    			$Tmptz = arraykeyToLower($Tmptz1) ; 
    			if($Tmpzl && $Tmptz ){
    				$ZlData =[];$TZData =[];
    				foreach ($Tmpzl as $kup=>&$vup)
    				{
    					if($insData['fkey'] == 'FSetHuiLvFaLang' && ($vup['fprodno'] == 'WINGD' or $vup['fname'] =='双燃料机型' or $vup['fname'] =='普通机型') ){
    						$ZlData[$kup]['fid'] = $vup['fid'];
    						$ZlData[$kup]['fexchangerate'] =  empty($insData['fvalue'])?0:$insData['fvalue'] ;
    						$ZlData[$kup]['fpatentfeeamount'] =   $ZlData[$kup]['fexchangerate'] * $vup['fpatentfee']  ;
    						
    					}
    					if($insData['fkey'] == 'FSetHuiLvOyuan' && ($vup['fprodno'] == 'MAN' or $vup['fname'] =='所有机型' ) )
    					{
    						$ZlData[$kup]['fid'] = $vup['fid'];
    						$ZlData[$kup]['fexchangerate'] =  empty($insData['fvalue'])?0:$insData['fvalue'] ;
    						$ZlData[$kup]['fpatentfeeamount'] =   $ZlData[$kup]['fexchangerate'] * $vup['fpatentfee']  ;
    					}
    				}
    				
    				foreach ($Tmptz as $kp=>&$vp)
    				{
    					if($insData['fkey'] == 'FSetHuiLvFaLang' && ($vp['fbrand'] == 'WINGD') ){
    						$TZData[$kp]['fid'] = $vp['fid'];
    						$TZData[$kp]['fexchangerate'] =  empty($insData['fvalue'])?0:$insData['fvalue'] ;
    						$TZData[$kp]['fallamount'] =  round($vp['ftzfeiyong']* $TZData[$kp]['fexchangerate'] ,2)   ;
    						//图纸合计 含税
    						$TZData[$kp]['ffaxallamount']  = round((floatval($vp['ftzfeiyong']*$TZData[$kp]['fexchangerate'])  )*(1+13/100) ,2)  ;
    						
    					}
    					if($insData['fkey'] == 'FSetHuiLvOyuan' && ($vp['fbrand'] == 'MAN' ) )
    					{
    						$TZData[$kp]['fid'] = $vp['fid'];
    						$TZData[$kp]['fexchangerate'] =  empty($insData['fvalue'])?0:$insData['fvalue'] ;
    						$TZData[$kp]['fallamount'] =  round($vp['ftzfeiyong']* $TZData[$kp]['fexchangerate'] ,2)  ;
    						//图纸合计 含税
    						$TZData[$kp]['ffaxallamount']  = round((floatval($vp['ftzfeiyong']*$TZData[$kp]['fexchangerate']) )*(1+13/100) ,2)  ;
    						
    					}
    				}
    				
    				$inszl = SqlServerUtil::sqlsrvkqUpdateTosql($this->SqlServer,'gz_Yzhuanlif',$ZlData,'fid');
    				
    				$instz = SqlServerUtil::sqlsrvkqUpdateTosql($this->SqlServer,'gz_Ytuzhif',$TZData,'fid');
    			
    				if( $insMX && $incenshu  && $inszl && $instz){
    					sqlsrv_commit($this->SqlServer);
    					showMsg(200,'成功!');
    				}else {
    					sqlsrv_rollback($this->SqlServer);
    					showMsg(400,'修改失败');
    				}
    				
    			}
    			
    		}
    		//专利合计修改
    		
    		//水电费 合计26011
    		if(in_array($insData['fkey'] , ['FSetShuiDianjgcjPrice'] ) ){
    			// 结构车间水电费  : 一种是按照吨位计算，即吨位单价乘以吨位；  一种是固定金额 fhanjiecj
    			// 结构车间吨位	fjgcjdw  -- 技术中心  ，，  自制件重量
    			// 结构车间吨位单价	fjgcjdwprice   -- 参数获取
    			$sqlSDF = " SELECT * FROM  gz_Yshuidianf  ";
    			$TmpSDF1 =  SqlServerUtil::execToSql($this->SqlServer, $sqlSDF   );
    			$TmpSDF = arraykeyToLower($TmpSDF1) ;
    			if($TmpSDF ){
    				$SDFData =[];
    				foreach ($TmpSDF as $kup=>&$vup)
    				{
    					$SDFData[$kup]['fid'] = $vup['fid'];
    					$SDFData[$kup]['fjgcjdwprice'] =  empty($insData['fvalue'])?0:$insData['fvalue'] ;
    					// 结构车间金额	fjgcjdwamount
    					$SDFData[$kup]['fjgcjdwamount'] =  ($vup['fjgcjdw']??0) * ($SDFData[$kup]['fjgcjdwprice']??0)  ;
    					//水电费合计
    					$SDFData[$kup]['fallamount'] =  ($SDFData[$kup]['fjgcjdwamount']??0) + ($vup['fjijiacj']??0 ) + ($vup['fzhuangshicj']??0 )  + ($vup['fhanjiecj']??0 ) ;
    					//水电费合计 含税
    					$SDFData[$kup]['ffaxallamount']  = (floatval($SDFData[$kup]['fjgcjdwamount'])  + floatval($vup['fjijiacj'])  + floatval($vup['fzhuangshicj']) + ($vup['fhanjiecj']??0 ))*(1+13/100)   ;
    				}
    				$inssdf = SqlServerUtil::sqlsrvkqUpdateTosql($this->SqlServer,'gz_Yshuidianf',$SDFData,'fid');
    				
    				if( $insMX && $incenshu  && $inssdf ){
    					sqlsrv_commit($this->SqlServer);
    					showMsg(200,'成功!');
    				}else {
    					sqlsrv_rollback($this->SqlServer);
    					showMsg(400,'修改失败');
    				}
    			}
    		}
    		//水电费 合计修改
    		
    		// 辅材成本(装试)   28007
    		if(in_array($insData['fkey'] , ['FSetFuCai550Value' ,'FSetFuCai535Value','FSetFuCaiBZW535Value','FSetFuCaiBZW550Value'] ) ){
    			// 低耗	包装物   -- 参数获取
//     			FSetFuCai535Value	辅材成本 -- 535计算值（辅料）
//     			FSetFuCai550Value	辅材成本 -- 550计算值（辅料）
//     			FSetFuCaiBZW535Value	辅材成本 -- 535计算值（包装物）
//     			FSetFuCaiBZW550Value	辅材成本 -- 550计算值（包装物）
    			$yy = $this->getSystemProfile(['fsetfucai535value','fsetfucai550value','fsetfucaibzw535value','fsetfucaibzw550value']);
    			$fucaibzwvalue = 0 ;
    			$fucaivalue =0 ;
    		
    			if(in_array($insData['fkey'] , [ 'FSetFuCai535Value','FSetFuCaiBZW535Value' ] )){
    				$sqlzs = " SELECT  v1.fid,v1.fbrand,v1.fmodel, v1.fdihao,v1.fbaozhuangwu,
					v1.fyoulvqi,v1.fqitayoupin,v1.ffentanfycj,v1.ffentanfysczl,
					u1.ffuliaopakeage, u1.ffuliao , u1.fpackage
					FROM  gz_Yfucaicbfzshi v1 left join gz_YBaseJS u1  on v1.fmodel = u1.fmodel
					where 1=1  and  u1.ffuliaopakeage = 535 ";
    				 
    				$fucaibzwvalue = empty($yy['fsetfucaibzw535value'])?0:$yy['fsetfucaibzw535value'] ;
    				$fucaivalue = empty($yy['fsetfucai535value'])?0:$yy['fsetfucai535value'] ;
    			}else{
    				$sqlzs = " SELECT v1.fid,v1.fmodel, v1.fdihao,v1.fbaozhuangwu,
					v1.fyoulvqi,v1.fqitayoupin,v1.ffentanfycj,v1.ffentanfysczl,
					u1.ffuliaopakeage, u1.ffuliao  , u1.fpackage
					FROM  gz_Yfucaicbfzshi v1 left join gz_YBaseJS u1  on v1.fmodel = u1.fmodel
					where 1=1  and  u1.ffuliaopakeage = 550 ";
    				$fucaibzwvalue = empty($yy['fsetfucaibzw550value'])?0: $yy['fsetfucaibzw550value'] ;
    				$fucaivalue = empty($yy['fsetfucai550value'])?0: $yy['fsetfucai550value'] ;
    			}
    		
    			$TmpZS1 =  SqlServerUtil::execToSql($this->SqlServer, $sqlzs   );
    			$TmpZS = arraykeyToLower($TmpZS1) ;
    			if($TmpZS ){
    				$ZSData =[];
    				foreach ($TmpZS as $kup=>&$vup)
    				{
    					$ZSData[$kup]['fid'] = $vup['fid'];
    					$ZSData[$kup]['fdihao'] = $vup['ffuliao']* $fucaivalue ;
    					$ZSData[$kup]['fbaozhuangwu'] = $vup['fpackage']* $fucaibzwvalue ;
    					$ZSData[$kup]['fallamount'] =  ($ZSData[$kup]['fdihao']??0) + ($ZSData[$kup]['fbaozhuangwu']??0 ) + ($vup['fyoulvqi']??0 )
    						+ ($vup['fqitayoupin']??0)  + ($vup['ffentanfycj']??0 ) + ($vup['ffentanfysczl']??0)  ;
    				}
    				$inszs = SqlServerUtil::sqlsrvkqUpdateTosql($this->SqlServer,'gz_Yfucaicbfzshi',$ZSData,'fid');
    				if( $insMX && $incenshu  && $inszs ){
    					sqlsrv_commit($this->SqlServer);
    					showMsg(200,'成功!');
    				}else {
    					sqlsrv_rollback($this->SqlServer);
    					showMsg(400,'修改失败');
    				}
    			}
    		}
    		//辅材成本(装试)修改
    		
    		//FSetFuCaiDWPrice -- 辅材焊接  26008
    		if(in_array($insData['fkey'] , ['FSetFuCaiDWPrice'] ) ){
    			//
    			$sqlHJ = " SELECT * FROM  gz_Yfucaicbf  ";
    			$TmpHJ1 =  SqlServerUtil::execToSql($this->SqlServer, $sqlHJ   );
    			$TmpHJ = arraykeyToLower($TmpHJ1) ;
    			if($TmpHJ ){
    				$HJData =[];
    				foreach ($TmpHJ as $kup=>&$vup)
    				{	
    					$HJData[$kup]['fid'] = $vup['fid'];
    					$HJData[$kup]['fdunweiprice'] = empty($insData['fvalue'])?0:$insData['fvalue'] ;
    					$HJData[$kup]['fdunweicb']  =  ($vup['fzzjweight']??0) *  $HJData[$kup]['fdunweiprice'] ;
    					$HJData[$kup]['fallamount'] =  ($vup['fzjyouqi']??0) + ($vup['ftuihuocb']??0 ) + ($vup['fqitaftcb']??0 ) + $HJData[$kup]['fdunweicb']??0  ;
    				}
    				$inshj = SqlServerUtil::sqlsrvkqUpdateTosql($this->SqlServer,'gz_Yfucaicbf',$HJData,'fid');
    				
    				if( $insMX && $incenshu  && $inshj ){
    					sqlsrv_commit($this->SqlServer);
    					showMsg(200,'成功!');
    				}else {
    					sqlsrv_rollback($this->SqlServer);
    					showMsg(400,'修改失败');
    				}
    			}
    		}
    		
    		//FSetFuCaiDWPrice -- 辅材机加  28006
    		if(in_array($insData['fkey'] , ['FSetProdFY'] ) ){
    			$sqlJJ = " SELECT * FROM  gz_Yfucaicbfjijia  ";
    			$TmpJJ1 =  SqlServerUtil::execToSql($this->SqlServer, $sqlJJ   );
    			$TmpJJ = arraykeyToLower($TmpJJ1) ;
    			if($TmpJJ ){
    				$JJData =[];
    				foreach ($TmpJJ as $kup=>&$vup)
    				{
    					$JJData[$kup]['fid'] = $vup['fid'];
    					$JJData[$kup]['fallamount']  =  empty($insData['fvalue'])?0:$insData['fvalue'] * $vup['fdaojufy']  + ($vup['ffentanfy']??0)  ;
    				}
    				$insjj = SqlServerUtil::sqlsrvkqUpdateTosql($this->SqlServer,'gz_Yfucaicbfjijia',$JJData,'fid');
    				
    				if( $insMX && $incenshu  && $insjj ){
    					sqlsrv_commit($this->SqlServer);
    					showMsg(200,'成功!');
    				}else {
    					sqlsrv_rollback($this->SqlServer);
    					showMsg(400,'修改失败');
    				}
    			}
    		}
    		
    		//船检费CCS
    		if(in_array($insData['fkey'] , ['FSetChuanjianCCS'] ) ){
    			$sqlCCS = " SELECT * FROM  gz_YchuanjianfCCS  ";
    			$TmpCCS1 =  SqlServerUtil::execToSql($this->SqlServer, $sqlCCS   );
    			$TmpCCS = arraykeyToLower($TmpCCS1) ;
    			if($TmpCCS ){
    				$CCSData =[];
    				foreach ($TmpCCS as $kup=>&$vup)
    				{
    					$CCSData[$kup]['fid'] = $vup['fid'];
    					// 合计   
    					$CCSData[$kup]['fchanjianfeiccs']  =  empty($insData['fvalue'])?0:round(($vup['fzjjianyanf'] + $vup['fnoxpaifangf']
    							+ $vup['flvtuf'] + $vup['fjizuojijiaf']	+ $vup['fzhusuf'] +   $vup['fjiaotongf']
    							+  $vup['ftongxunf']  +  $vup['fzhengshuf'])/$insData['fvalue'],2)   ;
    				}
    				$insccs = SqlServerUtil::sqlsrvkqUpdateTosql($this->SqlServer,'gz_YchuanjianfCCS',$CCSData,'fid');
    				
    				if( $insMX && $incenshu  && $insccs ){
    					sqlsrv_commit($this->SqlServer);
    					showMsg(200,'成功!');
    				}else {
    					sqlsrv_rollback($this->SqlServer);
    					showMsg(400,'修改失败');
    				}
    			}
    		}
    		
    		//运保费 
    		if(in_array($insData['fkey'] , ['FSetYunBaoF' , 'FSetTuZhiSS'] ) ){
    			$sqlyb = " SELECT * FROM  gz_Yyunbaof  ";
    			$TmpYB1 =  SqlServerUtil::execToSql($this->SqlServer, $sqlyb   );
    			$TmpYB = arraykeyToLower($TmpYB1) ;
    			$yb = $this->getSystemProfile([  'FSetYunBaoF' , 'FSetTuZhiSS' ]);
    			
    			if($TmpYB ){
    				$YBData =[];
    				foreach ($TmpYB as $kup=>&$vup)
    				{
    					$YBData[$kup]['fid'] = $vup['fid'];
    					// 合计
//     					empty($insData['fvalue'])?0:$insData['fvalue']
    					if(in_array($insData['fkey'] , ['FSetYunBaoF'  ]) ) {
    						
    						$YBData[$kup]['fallamount'] =  empty($insData['fvalue'])?0:round($vup['fbaoxianfei'] *(1+13/100) / $yb['fsettuzhiss'] ,2)
    						+  round(($vup['fyunshufei']+  $vup['fysguding'])*(1+13/100) / $insData['fvalue'] ,2)    ;
    						
						}else{
							$YBData[$kup]['fallamount'] =  empty($insData['fvalue'])?0:round($vup['fbaoxianfei'] *(1+13/100) / $insData['fvalue'] ,2)
							+  round(($vup['fyunshufei']+  $vup['fysguding'])*(1+13/100) / $yb['fsetyunbaof'] ,2)    ;
							
						}
    				
    				}
    				$insyb = SqlServerUtil::sqlsrvkqUpdateTosql($this->SqlServer,'gz_Yyunbaof',$YBData,'fid');
    				
    				if( $insMX && $incenshu  && $insyb ){
    					sqlsrv_commit($this->SqlServer);
    					showMsg(200,'成功!');
    				}else {
    					sqlsrv_rollback($this->SqlServer);
    					showMsg(400,'修改失败');
    				}
    			}
    		}
    		//运保费 26002
//     		
    		
    	}
    	//修改
    	if( $insMX && $incenshu  ){
    		sqlsrv_commit($this->SqlServer);
    		showMsg(200,'成功!');
    	}else {
    		sqlsrv_rollback($this->SqlServer);
    		showMsg(400,'修改失败');
    	}
    }
    
    /**
    * 报表分析  引入需求  -- 正式报价 30002
    * @date: 2023年4月11日 下午3:16:47
    * @author: juyi
    */
    public function BbfenxiAdd(Request $request){
    	$FRepKey = $request->get('FRepKey');
    	$opername= $request->get('opername');
    	$data =  $request->all() ;
    	$resData = $data['data'];
    	if(empty($resData)){
    		showMsg(400,'未选中数据信息') ;
    	}
    	$fbillno = $resData['fbillno'] ;
    	$db = columnBiao($FRepKey)   ; 	
    	$QDHTTemp = $this->getfenxiBB($fbillno, '30002' ,$FRepKey  );
    	 
    	if($QDHTTemp){
    		// SqlServerUtil::sqlsrvDeleteBack($this->SqlServer, $db , ['fjybjbillno'=> "'".$v['fbillno']."'" ],true);
    		SqlServerUtil::sqlsrvCreate($this->SqlServer , $db  , $QDHTTemp);
    	}else{
    		showMsg(400,' 数据信息为空 ') ;
    	}
    	
    	showMsg(0,' 成功') ;
    	 
    }
    
    public function BbfenxiSave(Request $request){
    	$FRepKey = $request->get('FRepKey');
    	$opername= $request->get('opername');
    	$data =  $request->all() ;
    	$resData = $data['data'];
    	if(empty($resData)){
    		showMsg(400,'未选中数据信息') ;
    	}
    	if($resData[0]['fstatus']>0){
    		showMsg(400,'已审核，无法编辑保存') ;
    	}
    	$fcustomerno = $resData[0]['fcustomerno'] ;
    	$fcustomernols = $resData[0]['fcustomernols'] ;
//     	dd($fcustomerno ,$resData );
    	if($fcustomerno == $fcustomernols){
    		showMsg(400,'项目号与历史项目号一致，请检查') ;
    	}
    	$db = columnBiao($FRepKey)   ;
    	$update= SqlServerUtil::exeupdateTosql($this->SqlServer,$db, ['fcustomerno'=>$fcustomerno,'fcustomernols'=>$fcustomernols], ['fid'=>$resData[0]['fid']]);
    	if($update){
    		showMsg(0,' 成功') ;
    	}else{
    		showMsg(400,' 失败  ') ;
    	}
    	
    }
    
    /**
    * 分析报表 U8 获取  2222222
    * @date: 2023年4月11日 下午5:27:41
    * @author: juyi
    */
    public function BbfenxiU8(Request $request){
    	$FRepKey = $request->get('FRepKey');
    	$opername= $request->get('opername');
    	$data =  $request->all() ;
    	$resData = $data['data'];
    	
    	$db = columnBiao($FRepKey) ;
    	if(empty($resData)){
    		showMsg(400,'数据为空，请选中一行');
    	}
    	//判断已经审核无法再获取U8
    	if( $resData[0]['fstatus']>0 ){
    		showMsg(400,'流水号：'.$resData[0]['fbillno'].' ，已经审核无法再获取U8');
    	}
    	//项目号
    	$xmh = $resData[0]['fcustomerno'] ;
    	$xmhls = $resData[0]['fcustomernols'] ;
    	
    	$xmhTmp = $resData[0]['fcustomerno'] ;
    	//单号
    	$fjybjbillno = $resData[0]['fbillno'] ;
    	
    	//判断  项目号历史是否 存在 gz_Ycaigoucbf_BAOJIA_FXBB , gz_Yjiazhangcbf_BAOJIA_FXBB
//     	$sql = "select * from  gz_Ycaigoucbf_BAOJIA_FXBB where  fcustomerno = '{$xmh}' ";
//     	$resxmhLS = SqlServerUtil::execToSql($this->SqlServer, $sql );
//     	$sqljz = "select * from  gz_Yjiazhangcbf_BAOJIA_FXBB where  fcustomerno = '{$xmh}' ";
//     	$resJZxmhLS = SqlServerUtil::execToSql($this->SqlServer, $sqljz );
//     	if( $resxmhLS || $resJZxmhLS){
//     		showMsg(400,'当前项目号（历史）已存在。 ') ;
//     	}
    	
    	// 启动事务
    	if (sqlsrv_begin_transaction($this->SqlServer) === false) {
    		die(print_r(sqlsrv_errors(), true));
    	}
    	$cg = true;
    	$jz = true;
    	//1.采购成本历史
    	$cgsql = "select fbrand,fprodno,fcode,0 as fallamount,fjybjbillno, '{$xmh}' as fcustomerno,2 AS fisqr  from  gz_Ycaigoucbf_BAOJIA
    	where  fjybjbillno = '{$fjybjbillno}'  ";
    	$resCG = SqlServerUtil::execToSql($this->SqlServer, $cgsql );
    	//建立连接
    	//     	$serverConnect  = $this->getDbConnect();
    	//     		if(!$serverConnect){
    	//     			showMsg(400,'连接数据库信息错误，请重试');
    	//     		}
    	
    	if($resCG){
    		//查询 U8 成本信息
    		$arrCode = array_column($resCG, 'fcode');
    		$fcode =join("','", $arrCode);
    		$fcodeStr = "'".$fcode ."'";
    		$sqlcgu8 = " select * from ";
    		$cgTmp =[];
    		//获取采购成本历史U8数据
    		//if($serverConnect){
    		//$cgTmp = SqlServerUtil::execToSql($serverConnect, $sqlcgu8 );
    		//}
    		
    		SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_Ycaigoucbf_BAOJIA_FXBB' , ['fjybjbillno'=> $fjybjbillno,'fcustomerno'=> $xmh ,'fisqr'=>2 ] );
    		$cg =SqlServerUtil::sqlsrvAllTosql($this->SqlServer,'gz_Ycaigoucbf_BAOJIA_FXBB' ,$resCG);
    	}
    	
    	//2.采购加账历史
    	$cgsql = "select fbrand,fprodno,fcode,0 as fallamount,fsxqty,fzscjprice,fjybjbillno,fyzamount,fax,fqty,fzjqty,fname,fbm,fdanweibumen,
    	fywqty,foriamount,'{$xmh}' as fcustomerno,2 AS fisqr  from  gz_Yjiazhangcbf_BAOJIA  where  fjybjbillno = '{$fjybjbillno}' and fbm ='CG'  ";
    	$resJZ = SqlServerUtil::execToSql($this->SqlServer, $cgsql );
    	if($resJZ){
    		//查询 U8 成本信息
    		$arrJZ = array_column($resJZ, 'fcode');
    		$fcodejz =join("','", $arrJZ);
    		$fcodejzStr = "'".$fcodejz ."'";
    		$sqlcgu8 = " select * from  ";
    		$cgTmp =[];
    		//获取加账历史U8数据
    		//$jzTmp = SqlServerUtil::execToSql($serverConnect, $sqlcgu8 );
    		
    		SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_Yjiazhangcbf_BAOJIA_FXBB' , ['fjybjbillno'=> $fjybjbillno,'fbm'=>'CG','fcustomerno'=> $xmh ,'fisqr'=>2] );
    		$jz =SqlServerUtil::sqlsrvAllTosql($this->SqlServer,'gz_Yjiazhangcbf_BAOJIA_FXBB' ,$resJZ);
    	}
    	if( $cg && $jz ){
    		sqlsrv_commit($this->SqlServer);
    		showMsg(0,'成功');
    	}else {
    		sqlsrv_rollback($this->SqlServer);
    		showMsg(1,'失败');
    	}
    	
    }
    
    /**
     * 报表分析 项目号历史  U8   --- 历史   历史    1
     * @date: 2023年4月20日 下午2:55:06
     * @author: juyi
     */
    public function BbfenxilsU8(Request $request){
    	$FRepKey = $request->get('FRepKey');
    	$opername= $request->get('opername');
    	$data =  $request->all() ;
    	$resData = $data['data'];
    	$db = columnBiao($FRepKey) ;
    	if(empty($resData)){
    		showMsg(400,'数据为空，请选中一行');
    	}
    	//判断已经审核无法再获取U8
    	if( $resData[0]['fstatus']>0 ){
    		showMsg(400,'流水号：'.$resData[0]['fbillno'].' ，已经审核无法再获取U8');
    	}
    	//项目号
    	$xmh = $resData[0]['fcustomerno'] ;
    	$xmhls = $resData[0]['fcustomernols'] ;
    	
    	//单号
    	$fjybjbillno = $resData[0]['fbillno'] ;
    	//判断  项目号历史是否 存在 gz_Ycaigoucbf_BAOJIA_FXBB , gz_Yjiazhangcbf_BAOJIA_FXBB
//     	$sql = "select fcustomerno from  gz_Ycaigoucbf_BAOJIA_FXBB where  fcustomerno = '{$xmhls}' ";
//     	$resxmhLS = SqlServerUtil::execToSql($this->SqlServer, $sql );
//     	$sqljz = "select fcustomerno from  gz_Yjiazhangcbf_BAOJIA_FXBB where  fcustomerno = '{$xmhls}' ";
//     	$resJZxmhLS = SqlServerUtil::execToSql($this->SqlServer, $sqljz );
//     	if( $resxmhLS || $resJZxmhLS){
//     		showMsg(400,'当前项目号（历史）已存在。 ') ;
//     	}

    	// 启动事务
    	if (sqlsrv_begin_transaction($this->SqlServer) === false) {
    		die(print_r(sqlsrv_errors(), true));
    	}
    	$cgls = true;
    	$jzls = true;
    	//1.采购成本历史 
    	$cgsql = "select fbrand,fprodno,fcode,0 as fallamount,fjybjbillno, '{$xmhls}' as fcustomerno,1 AS fisqr  from  gz_Ycaigoucbf_BAOJIA 
    			where  fjybjbillno = '{$fjybjbillno}'  ";
    	$resCG = SqlServerUtil::execToSql($this->SqlServer, $cgsql );
    	//建立连接
//     	$serverConnect  = $this->getDbConnect();
    	//     		if(!$serverConnect){
    	//     			showMsg(400,'连接数据库信息错误，请重试');
    	//     		}
    	
    	if($resCG){
    		//查询 U8 成本信息
    		$arrCode = array_column($resCG, 'fcode');
    		$fcode =join("','", $arrCode);
    		$fcodeStr = "'".$fcode ."'";
    		$sqlcgu8 = " select * from ";
    		$cgTmp =[];
    		//获取采购成本历史U8数据
    		//if($serverConnect){
    			//$cgTmp = SqlServerUtil::execToSql($serverConnect, $sqlcgu8 );
    		//}
    		
    		SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_Ycaigoucbf_BAOJIA_FXBB' , ['fjybjbillno'=> $fjybjbillno,'fcustomerno'=> $xmhls,'fisqr'=>1 ] );
    		$cgls =SqlServerUtil::sqlsrvAllTosql($this->SqlServer,'gz_Ycaigoucbf_BAOJIA_FXBB' ,$resCG);
    	}
    	
    	//2.采购加账历史 
    	$cgsql = "select fbrand,fprodno,fcode,0 as fallamount,fsxqty,fzscjprice,fjybjbillno,fyzamount,fax,fqty,fzjqty,fname,fbm,fdanweibumen, 
			fywqty,foriamount,'{$xmhls}' as fcustomerno ,1 AS fisqr from  gz_Yjiazhangcbf_BAOJIA  where  fjybjbillno = '{$fjybjbillno}' and fbm ='CG'  ";
    	$resJZ = SqlServerUtil::execToSql($this->SqlServer, $cgsql );
    	if($resJZ){
    		//查询 U8 成本信息
    		$arrJZ = array_column($resJZ, 'fcode');
    		$fcodejz =join("','", $arrJZ);
    		$fcodejzStr = "'".$fcodejz ."'";
    		$sqlcgu8 = " select * from  ";
    		$cgTmp =[];
    		//获取加账历史U8数据
    		//$jzTmp = SqlServerUtil::execToSql($serverConnect, $sqlcgu8 );
    		
    		SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_Yjiazhangcbf_BAOJIA_FXBB' , ['fjybjbillno'=> $fjybjbillno,'fbm'=>'CG','fcustomerno'=> $xmhls ,'fisqr'=>1 ] );
    		$jzls =SqlServerUtil::sqlsrvAllTosql($this->SqlServer,'gz_Yjiazhangcbf_BAOJIA_FXBB' ,$resJZ);
    	}
    	if( $cgls && $jzls ){
    		sqlsrv_commit($this->SqlServer);
    		showMsg(0,'成功');
    	}else {
    		sqlsrv_rollback($this->SqlServer);
    		showMsg(1,'失败');
    	}
    	
    }
    
    
    /**
     * 报表分析  gz_Yfenxibiao --  50001
     * @date: 2023年4月11日 下午3:16:47
     * @author: juyi
     * 报价系统从现有的U8系统抽取历史成本数据及
     * 项目实际发生的成本数据，
     * （柴油机考虑按照项目加名称加组号抽取数据）
     */
    public function Bbfenxi(Request $request){
    	$FRepKey = $request->get('FRepKey');
    	$opername= $request->get('opername');
    	$data =  $request->all() ;
    	$resData = $data['data'];
    	 
    	$db = columnBiao($FRepKey) ;
    	if(empty($resData)){
    		showMsg(400,'数据为空，请选中一行');
    	}
    	//项目号
    	$xmh = $resData[0]['fcustomerno'] ;
    	$xmhls = $resData[0]['fcustomernols'] ;
    	
    	$xmhTmp = $resData[0]['fcustomerno'] ;
    	//单号
    	$fjybjbillno = $resData[0]['fbillno'] ; 
    	//项目号 + 项目号历史
    	
    	//1.采购成本 
    	
    	
    	//2.采购加账 
    	
    	
    	//3. 
    	
    	
    	
    	
    	showMsg(0,'成功' ,$data );
    }
    
    /**
    * 分析报表 -- 采购成本
    * @date: 2023年4月20日 下午3:45:04
    * @author: juyi
    */
    public function Bbfenxicgcb(Request $request){
    	$FRepKey = $request->get('FRepKey');
    	$opername= $request->get('opername');
    	$data =  $request->all() ;
    	$resData = $data['data'];
    	$fislishi = $request->fislishi??0 ;
    	if(empty($resData)){
    		showMsg(400,'数据为空，请检查');
    	}
    	//  0 - 不是  fcustomerno ，1 --  历史  fcustomernols
    	$xmh = $resData[0]['fcustomerno'] ;
    	$xmhls = $resData[0]['fcustomernols'] ;
    	
    	$xmhTmp = $resData[0]['fcustomerno'] ; 
    	//单号
    	$fjybjbillno = $resData[0]['fbillno'] ; 
    	//采购成本历史
    	if($fislishi == 1 ){
    		if(empty($xmhls)){
    			showMsg(400,  '订单号：'.$fjybjbillno.' ,项目号历史为空');
    		}
    		$xmhTmp = $resData[0]['fcustomernols'] ;
    		$sql =" set nocount on
    		if object_id('tempdb..#BBLStmpprodnoCG') is not null drop table #BBLStmpprodnoCG
    		create table #BBLStmpprodnoCG(
    		fid int identity(1,1),
    		fprodno varchar(200),
    		fcustomerno varchar(200)
    		)
    		insert into #BBLStmpprodnoCG(fprodno,fcustomerno)
    		select u1.fprodno, min(t1.fcustomerno) fcustomerno  from gz_Ycaigoucbf_BAOJIA  u1
    		LEFT JOIN gz_Ycaigoucbf_BAOJIA_FXBB t1 on t1.fjybjbillno = u1.fjybjbillno and t1.fisqr =1
    		where 1=1  and u1.fjybjbillno='{$fjybjbillno}' and t1.fisqr =1 AND t1.fcustomerno ='{$xmhls}' group by u1.fprodno
    		
    		declare @sqlmax varchar(max),@filvalue varchar(200),@filvaluej varchar(200)
    		declare @i int ,@rwcount int   ,@j int ,@rwcountj int
    		declare @strvalue1 varchar(200),@strvalue2 varchar(200)
    		set @i=1
    		select @rwcount=count(1),@rwcountj =count(1) from #BBLStmpprodnoCG
    		set @sqlmax='select u1.fcode as ''代码'',v1.fname as ''名称'' '
    		while @i<=@rwcount
    		begin
    		select @filvalue=fprodno from #BBLStmpprodnoCG where fid=@i
    		set @strvalue1='case when u1.fprodno='''+@filvalue+''' then isnull(u1.fallAmount,0) else 0 end'
    		set @sqlmax=@sqlmax+',case when u1.fprodno='''+@filvalue+''' then isnull(u1.fallAmount,0) else 0 end as ['+ @filvalue +']'
    		set @i=@i+1
    		end
    		
    		set @i=1
    		while @i<=@rwcountj
    		begin
    		select @filvaluej=fprodno,@filvalue=fcustomerno from #BBLStmpprodnoCG where fid=@i
    		set @strvalue2='case when fx.fprodno='''+@filvaluej+''' then isnull(fx.fallAmount,0) else 0 end'
    		set @sqlmax=@sqlmax+',case when fx.fprodno='''+@filvaluej+''' then isnull(fx.fallAmount,0) else 0 end as ['+ @filvalue +']'
    		set @i=@i+1
    		end
    		
    		set @sqlmax=@sqlmax+' ,'+ @strvalue1+' -'+ @strvalue2 +' as ''利差'' '
    		
    		set @sqlmax=@sqlmax+ ' from gz_Ycaigoucbf_BAOJIA  u1 inner join gz_YcaigoucbfSet v1 on u1.fcode=v1.fcode
    		LEFT JOIN gz_Ycaigoucbf_BAOJIA_FXBB fx on fx.fjybjbillno = u1.fjybjbillno  and u1.fcode=fx.fcode and fx.fisqr =1
    		where 2=2 and u1.fjybjbillno=''{$fjybjbillno}'' and fx.fcustomerno =''{$xmhTmp}'' and fx.fisqr =1 '
    		exec( @sqlmax)";
    		
    	}else{
    		if(empty($xmh)){
    			showMsg(400, '订单号：'.$fjybjbillno.' ,项目号为空');
    		}
    		$sql =" set nocount on
    		if object_id('tempdb..#BBtmpprodnoCG') is not null drop table #BBtmpprodnoCG
    		create table #BBtmpprodnoCG(
    		fid int identity(1,1),
    		fprodno varchar(200),
    		fcustomerno varchar(200)
    		)
    		insert into #BBtmpprodnoCG(fprodno,fcustomerno)
    		select u1.fprodno, min(t1.fcustomerno) fcustomerno  from gz_Ycaigoucbf_BAOJIA  u1
    		LEFT JOIN gz_Ycaigoucbf_BAOJIA_FXBB t1 on t1.fjybjbillno = u1.fjybjbillno and t1.fisqr =2
    		where 1=1  and u1.fjybjbillno='{$fjybjbillno}' and t1.fisqr =2 AND t1.fcustomerno ='{$xmh}'  group by u1.fprodno
    		
    		declare @sqlmax varchar(max),@filvalue varchar(200),@filvaluej varchar(200)
    		declare @i int ,@rwcount int   ,@j int ,@rwcountj int
    		declare @strvalue1 varchar(200),@strvalue2 varchar(200)
    		set @i=1
    		select @rwcount=count(1),@rwcountj =count(1) from #BBtmpprodnoCG
    		set @sqlmax='select u1.fcode as ''代码'',v1.fname as ''名称'' '
    		while @i<=@rwcount
    		begin
    		select @filvalue=fprodno from #BBtmpprodnoCG where fid=@i
    		set @strvalue1='case when u1.fprodno='''+@filvalue+''' then isnull(u1.fallAmount,0) else 0 end'
    		set @sqlmax=@sqlmax+',case when u1.fprodno='''+@filvalue+''' then isnull(u1.fallAmount,0) else 0 end as ['+ @filvalue +']'
    		set @i=@i+1
    		end
    		
    		set @i=1
    		while @i<=@rwcountj
    		begin
    		select @filvaluej=fprodno,@filvalue=fcustomerno from #BBtmpprodnoCG where fid=@i
    		set @strvalue2='case when fx.fprodno='''+@filvaluej+''' then isnull(fx.fallAmount,0) else 0 end'
    		set @sqlmax=@sqlmax+',case when fx.fprodno='''+@filvaluej+''' then isnull(fx.fallAmount,0) else 0 end as ['+ @filvalue +']'
    		set @i=@i+1
    		end
    		
    		set @sqlmax=@sqlmax+' ,'+ @strvalue1+' -'+ @strvalue2 +' as ''利差'' '
    		
    		set @sqlmax=@sqlmax+ ' from gz_Ycaigoucbf_BAOJIA  u1 inner join gz_YcaigoucbfSet v1 on u1.fcode=v1.fcode
    		LEFT JOIN gz_Ycaigoucbf_BAOJIA_FXBB fx on fx.fjybjbillno = u1.fjybjbillno  and u1.fcode=fx.fcode and fx.fisqr =2
    		where 2=2 and u1.fjybjbillno=''{$fjybjbillno}'' and fx.fcustomerno =''{$xmhTmp}'' and fx.fisqr =2'
    		exec( @sqlmax)";
    		
    		
    	}
    	$keywordStr = "";
    	
    	
//     	$sql = str_replace('2=2',$keywordStr ,$sql );
    	
//     	echo $sql ;die;
    	$data = SqlServerUtil::execTosqlYes($this->SqlServer, $sql );
    	//dd($data);
    	if($data){
    		foreach ($data as $k => &$v)
    		{
    			foreach ($v as $k1=>$v1)
    			{
    				if( $v[$k1] ==='.00' || $v[$k1] ==='.000' || $v[$k1] ==='.0000' || ($v[$k1]>0 && $v[$k1]<1)  ){
    					$v[$k1] = floatval($v1);
    				}
    			}
    		}
    	}
    	showMsg(0,'成功' ,$data );
    	
    }
    
    
    /** 
    * 分析报表 加账成本    
    * @date: 2023年4月20日 下午6:27:07
    * @author: juyi
    */
    public function Bbfenxijzcb(Request $request){
    	$FRepKey = $request->get('FRepKey');
    	$opername= $request->get('opername');
    	$data =  $request->all() ;
    	$resData = $data['data'];
    	$fislishi = $request->fislishi??0 ;
    	if(empty($resData)){
    		showMsg(400,'数据为空，请检查');
    	}
    	//  0 - 不是  fcustomerno ，1 --  历史  fcustomernols
    	$xmh = $resData[0]['fcustomerno'] ;
    	$xmhls = $resData[0]['fcustomernols'] ;
    	 
    	$xmhTmp = $resData[0]['fcustomerno'] ;
    	//单号
    	$fjybjbillno = $resData[0]['fbillno'] ;
    	//jz成本历史
    	if($fislishi == 1 ){
    		if(empty($xmhls)){
    			showMsg(400,'订单号：'.$fjybjbillno.' ,项目号历史为空');
    		}
    		$xmhTmp = $resData[0]['fcustomernols'] ;
    		$sql =" set nocount on
    		if object_id('tempdb..#BBLStmpprodnoJZ') is not null drop table #BBLStmpprodnoJZ
    		create table #BBLStmpprodnoJZ(
    		fid int identity(1,1),
    		fprodno varchar(200),
    		fcustomerno varchar(200)
    		)
    		insert into #BBLStmpprodnoJZ(fprodno,fcustomerno)
    		select u1.fprodno, min(t1.fcustomerno) fcustomerno  from gz_Yjiazhangcbf_BAOJIA  u1
    		LEFT JOIN gz_Yjiazhangcbf_BAOJIA_FXBB t1 on t1.fjybjbillno = u1.fjybjbillno  and t1.fisqr =1
    		where 1=1  and u1.fjybjbillno='{$fjybjbillno}' and u1.Fbm ='CG'  and t1.fisqr =1 AND t1.fcustomerno ='{$xmhls}'    group by u1.fprodno
    		
    		declare @sqlmax varchar(max),@filvalue varchar(200),@filvaluej varchar(200)
    		declare @i int ,@rwcount int   ,@j int ,@rwcountj int
    		declare @strvalue1 varchar(200),@strvalue2 varchar(200)
    		set @i=1
    		select @rwcount=count(1),@rwcountj =count(1) from #BBLStmpprodnoJZ
    		set @sqlmax='select u1.fcode as ''代码'',v1.fname as ''名称'' '
    		while @i<=@rwcount
    		begin
    		select @filvalue=fprodno from #BBLStmpprodnoJZ where fid=@i
    		set @strvalue1='case when u1.fprodno='''+@filvalue+''' then isnull(u1.fallAmount,0) else 0 end'
    		set @sqlmax=@sqlmax+',case when u1.fprodno='''+@filvalue+''' then isnull(u1.fallAmount,0) else 0 end as ['+ @filvalue +']'
    		set @i=@i+1
    		end
    		
    		set @i=1
    		while @i<=@rwcountj
    		begin
    		select @filvaluej=fprodno,@filvalue=fcustomerno from #BBLStmpprodnoJZ where fid=@i
    		set @strvalue2='case when fx.fprodno='''+@filvaluej+''' then isnull(fx.fallAmount,0) else 0 end'
    		set @sqlmax=@sqlmax+',case when fx.fprodno='''+@filvaluej+''' then isnull(fx.fallAmount,0) else 0 end as ['+ @filvalue +']'
    		set @i=@i+1
    		end
    		
    		set @sqlmax=@sqlmax+' ,'+ @strvalue1+' -'+ @strvalue2 +' as ''利差'' '
    		set @sqlmax=@sqlmax+ ' from gz_Yjiazhangcbf_BAOJIA  u1 inner join gz_YjiazhangcbfSet v1 on u1.fcode=v1.fcode
    		LEFT JOIN gz_Yjiazhangcbf_BAOJIA_FXBB fx on fx.fjybjbillno = u1.fjybjbillno  and u1.fcode=fx.fcode  and fx.fisqr =1
    		where 2=2 and u1.fjybjbillno=''{$fjybjbillno}''  and u1.Fbm =''CG'' and fx.fcustomerno =''{$xmhTmp}''  and fx.fisqr =1'
    		exec( @sqlmax) 	";
    	}else{
    		if(empty($xmh)){
    			showMsg(400,'订单号：'.$fjybjbillno.' ,项目号为空');
    		}
    		$sql =" set nocount on
    		if object_id('tempdb..#BBtmpprodnoJZ') is not null drop table #BBtmpprodnoJZ
    		create table #BBtmpprodnoJZ(
    		fid int identity(1,1),
    		fprodno varchar(200),
    		fcustomerno varchar(200)
    		)
    		insert into #BBtmpprodnoJZ(fprodno,fcustomerno)
    		select u1.fprodno, min(t1.fcustomerno) fcustomerno  from gz_Yjiazhangcbf_BAOJIA  u1
    		LEFT JOIN gz_Yjiazhangcbf_BAOJIA_FXBB t1 on t1.fjybjbillno = u1.fjybjbillno and t1.fisqr =2
    		where 1=1  and u1.fjybjbillno='{$fjybjbillno}' and u1.Fbm ='CG' and t1.fisqr =2  AND t1.fcustomerno ='{$xmh}' group by u1.fprodno
    		
    		declare @sqlmax varchar(max),@filvalue varchar(200),@filvaluej varchar(200)
    		declare @i int ,@rwcount int   ,@j int ,@rwcountj int
    		declare @strvalue1 varchar(200),@strvalue2 varchar(200)
    		set @i=1
    		select @rwcount=count(1),@rwcountj =count(1) from #BBtmpprodnoJZ
    		set @sqlmax='select u1.fcode as ''代码'',v1.fname as ''名称'' '
    		while @i<=@rwcount
    		begin
    		select @filvalue=fprodno from #BBtmpprodnoJZ where fid=@i
    		set @strvalue1='case when u1.fprodno='''+@filvalue+''' then isnull(u1.fallAmount,0) else 0 end'
    		set @sqlmax=@sqlmax+',case when u1.fprodno='''+@filvalue+''' then isnull(u1.fallAmount,0) else 0 end as ['+ @filvalue +']'
    		set @i=@i+1
    		end
    		
    		set @i=1
    		while @i<=@rwcountj
    		begin
    		select @filvaluej=fprodno,@filvalue=fcustomerno from #BBtmpprodnoJZ where fid=@i
    		set @strvalue2='case when fx.fprodno='''+@filvaluej+''' then isnull(fx.fallAmount,0) else 0 end'
    		set @sqlmax=@sqlmax+',case when fx.fprodno='''+@filvaluej+''' then isnull(fx.fallAmount,0) else 0 end as ['+ @filvalue +']'
    		set @i=@i+1
    		end
    		
    		set @sqlmax=@sqlmax+' ,'+ @strvalue1+' -'+ @strvalue2 +' as ''利差'' '
    		set @sqlmax=@sqlmax+ ' from gz_Yjiazhangcbf_BAOJIA  u1 inner join gz_YjiazhangcbfSet v1 on u1.fcode=v1.fcode
    		LEFT JOIN gz_Yjiazhangcbf_BAOJIA_FXBB fx on fx.fjybjbillno = u1.fjybjbillno  and u1.fcode=fx.fcode and fx.fisqr =2
    		where 2=2 and u1.fjybjbillno=''{$fjybjbillno}''  and u1.Fbm =''CG'' and fx.fcustomerno =''{$xmhTmp}''  and fx.fisqr =2 '
    		exec( @sqlmax) 	";
    	}
    	
    	
    	$keywordStr = "";
    	
    	
    	
//     	echo $sql ;die;
    	$data = SqlServerUtil::execTosqlYes($this->SqlServer, $sql );
//     	dd($data);
    	if($data){
    		foreach ($data as $k => &$v)
    		{
    			foreach ($v as $k1=>$v1)
    			{
    				if( $v[$k1] ==='.00' || $v[$k1] ==='.000' || $v[$k1] ==='.0000' || ($v[$k1]>0 && $v[$k1]<1)  ){
    					$v[$k1] = floatval($v1);
    				}
    			}
    		}
    	}
    	showMsg(0,'成功' ,$data );
    }
    
    
    /**
    * 已完成
    * @date: 2023年4月12日 下午3:54:40
    * @author: juyi
    */
    public function Zswancheng(Request $request){
    	//
    	$FRepKey = $request->get('FRepKey');
    	$opername= $request->get('opername');
    	$data =  $request->all() ;
    	$resData = $data['data']; 
    	$db = columnBiao($FRepKey) ;
    	if(empty($resData)){
    		showMsg(400, '数据为空');
    	}
    	$fid = $request->fid ;
    	$fisqr =$request->fisqr??0 ;
    	$FidStr ="" ;
    	if ($request->has('fid') and $request->fid != '' and !empty($request->fid)) {
    		$FidStr=" and fid in ($fid) ";
    	}
    	foreach ($resData as $k =>$v)
    	{
    		if($v['fisqr'] >0){
    			showMsg(400,'该订单'.$v['fbillno'].' ，已完成');
    		}
    		if($v['fstatus'] <1){
    			showMsg(400,'该订单'.$v['fbillno'].' ，未审核');
    		}
    	}
    	if($fisqr == 0 ){
    		//未完成
    		$sql="update {$db} set Fisqr = 0 where 1=1 {$FidStr}   ";
    	}else{
    		$sql="update {$db} set Fisqr = 1  where 1=1 {$FidStr}   ";
    	}
    	// 启动事务
    	if (sqlsrv_begin_transaction($this->SqlServer) === false) {
    		die(print_r(sqlsrv_errors(), true));
    	}
    	
    	$sqlStr = iconv( 'UTF-8','GBK',$sql);
    	$up = sqlsrv_query($this->SqlServer, $sqlStr);
    	if($up ){
    		sqlsrv_commit($this->SqlServer);
    		showMsg(0,'成功');
    	}else {
    		sqlsrv_rollback($this->SqlServer);
    		showMsg(1,'失败');
    	}
    	
    }
    
    /**
    * 正式报价 -- 采购 -- 技术 -其他 是否加账明细
    * @date: 2023年4月12日 下午7:03:30
    * @author: juyi
    */
    public function getZSBaoJiaMX(Request $request){
    	$FRepKey = $request->get('FRepKey');
    	$opername = $request->get('opername');
    	$fbrand = $request->get('fbrand');
    	$fmodel = $request->get('fmodel');
    	//经营报价
    	$fjybjbillno = $request->get('fjybjbillno');
    	$fjzdetail = $request->get('fjzdetail')??0;
    	$baseSql ='';
    	$fdanweibumen = $request->get('fdanweibumen');
    	$fkeywordStr  = "" ;
    	$data = $request->data;
    	if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
    		$keyword = $request->keyword  ;
    		$fkeywordStr=" and ( charindex('{$keyword}',u1.fname)>0 or charindex('{$keyword}',u1.fcode)>0   )" ;
    	}
    	
    	$bumenStr = "";
    	if($fdanweibumen  == 1){
    		//采购部
    		$bumenName ="采购";
    		$bumenStr=" and ( charindex('{$bumenName}',u1.fdanweibumen)>0   )" ;
    		
    	}elseif($fdanweibumen  == 2){
    		//技术中心
    		$bumenName ="技术";
    		$bumenStr=" and ( charindex('{$bumenName}',u1.fdanweibumen)>0   )" ;
    	}elseif($fdanweibumen  == 3){
    		//其他部门    =  售后服务部、生产管理部  ， 质量管理部
    		$bumenName ="售后";
    		$bumenName1 ="生产";
    		$bumenName2 ="质量";
    		$bumenName3 ="其他";
    		$bumenStr=" and ( charindex('{$bumenName}',u1.fdanweibumen)>0  or charindex('{$bumenName1}',
				u1.fdanweibumen)>0 or charindex('{$bumenName2}',u1.fdanweibumen)>0 or charindex('{$bumenName3}',u1.fdanweibumen)>0 )" ;
    	}
    	
    	if($FRepKey == '14011'){
    		//技术
    		$baseSql ="  select row_number() OVER(ORDER BY v1.fcode  )   as N'序号',   u1.fbrand as N'品牌',v1.fcode as N'代码',v1.fprodno as N'机型',u1.fdanweibumen as '部门',
					u1.fname as N'名称',u1.fzjQty as N'单位',v1.fywqty as N'数量'  ,
				  case when u1.fdanweibumen  = '技术中心' then t1.fallAmount else 0 end as N'最新单价',
				  case when u1.fdanweibumen  = '技术中心' then t2.fallAmount else 0 end as N'本次确认的金额',
				  case when u1.fdanweibumen  = '技术中心' then t2.foriamount else 0 end as N'本次确认的单价',
  				  v1.fnote as N'备注'
    				from gz_Yjiazhangcbf v1  left join gz_YjiazhangcbfSet u1 on u1.fcode =  v1.fcode
					left join gz_YjiazhangcbfMX  t1 on t1.fcode = v1.fcode  and t1.fprodno = v1.fprodno 
					left join gz_Yjiazhangcbf_BAOJIA  t2 on t2.fcode = v1.fcode  and t2.fjybjbillno = v1.fbillno 
					and t2.fscjzID = v1.fid  and  t2.Fbm ='JS'
    				where 1=1 and v1.fbillno = '{$fjybjbillno}' {$bumenStr} {$fkeywordStr}";
    		
    	}elseif($FRepKey == '14012'){
    		//采购
    		$baseSql ="  select row_number() OVER(ORDER BY v1.fcode ) as N'序号', u1.fbrand as N'品牌',v1.fcode as N'代码',v1.fprodno as N'机型',u1.fdanweibumen as '部门',
					u1.fname as N'名称',u1.fzjQty as N'单位',v1.fywqty as N'数量'  ,
				  case when u1.fdanweibumen  = '采购部' then t1.fallAmount else 0 end as N'最新单价',
				  case when u1.fdanweibumen  = '采购部' then t2.fallAmount else 0 end as N'本次确认的金额', 
				  case when u1.fdanweibumen  = '采购部' then t2.foriamount else 0 end as N'本次确认的单价',
					v1.fnote  as N'备注'
    				from gz_Yjiazhangcbf v1  left join gz_YjiazhangcbfSet u1 on u1.fcode =  v1.fcode
					left join gz_YjiazhangcbfMX  t1 on t1.fcode = v1.fcode  and t1.fprodno = v1.fprodno
					left join gz_Yjiazhangcbf_BAOJIA  t2 on t2.fcode = v1.fcode  and t2.fjybjbillno = v1.fbillno 
					and t2.fscjzID = v1.fid  and  t2.Fbm ='CG'
    				where 1=1 and v1.fbillno = '{$fjybjbillno}' {$bumenStr} {$fkeywordStr} ";
    	}elseif($FRepKey == '14013'){
    		//财务
    		$baseSql ="  select row_number() OVER(ORDER BY v1.fcode  ) as N'序号', u1.fbrand as N'品牌',v1.fcode as N'代码',v1.fprodno as N'机型',u1.fdanweibumen as '部门',
					u1.fname as N'名称',u1.fzjQty as N'单位',v1.fywqty as N'数量'  ,
				t1.fallAmount as N'最新单价', t2.fallAmount as N'本次确认的金额' ,t2.foriamount as N'本次确认的单价' ,v1.fnote as N'备注' 
					from gz_Yjiazhangcbf v1  left join gz_YjiazhangcbfSet u1 on u1.fcode =  v1.fcode
					left join gz_YjiazhangcbfMX  t1 on t1.fcode = v1.fcode  and t1.fprodno = v1.fprodno 
					left join gz_Yjiazhangcbf_BAOJIA  t2 on t2.fcode = v1.fcode and t2.fscjzID = v1.fid  and t2.fjybjbillno = v1.fbillno  
    				where 1=1 and v1.fbillno = '{$fjybjbillno}' {$bumenStr} {$fkeywordStr} ";
    	}
//     	echo  $baseSql ; die;     
    	$res = SqlServerUtil::execTosqlOKTO($this->SqlServer,  $baseSql);
    	//     			dd($res);
    	$SCRCG =[];
    	if( in_array($FRepKey , [ '14012','14013'])  && $res){
    		//SCR 数据
    		$SCRCG  = SqlServerUtil::execToSql($this->SqlServer, "SELECT fpowerkw,hpscrl,hpscrh,lpscrl,lpscrh  FROM gz_YSCRSet  " );
        }
    	
    	$result =[];
    	if($res){
    		$result = arraykeyToLower($res);
    		$fhtpower = $data['fhtpower'];
    		foreach ($result as $k1=>&$v1)
    		{
    			if(  in_array($FRepKey , [ '14012','14013']) ){
    				if( stripos( $v1['名称'] , 'PSCR' ) !== false){
    					// 这里 要改 
    					if(substr(trim( $v1['名称']),1,4) == 'PSCR') {
    						$v1['最新单价'] = getSCRVal($SCRCG ,$fhtpower , $v1['代码'] );
    					}
    				}
    			}
    			
    			foreach ($v1 as $k2=>$v2)
    			{
    				if( $v1[$k2] ==='.00' || $v1[$k2]  ==='.0000'  || $v1[$k2]  ==='.000' || $v1[$k2]  ==='.000000' || ($v1[$k2]>0 && $v1[$k2]<1) ){
    					$v1[$k2] = floatval($v2);
    				}
    				// fnbfhyx
    			}
    		}
    	}
    	showMsg(0,'成功' , $result) ;
    	
    }
    
    /**
    *正式报价 备注  
    * @date: 2023年4月27日 下午8:18:33
    * @author: juyi
    */
    public function zsbjscd(Request $request){
    	$result=[];
    	$FRepKey = $request->get('FRepKey');
    	$opername = $request->get('opername');
    	$fbillno = $request->get('fbillno');
    	$data = $request->get('data');
    	if(empty($data)){
    		showMsg(400,'数据为空'  );
    	}
    	if( in_array($FRepKey, [ '34004' ]) ){
    		//加账 
    		$fbillnoentry = $request->get('fbillnoentry');
    		$data['fbillnoentry']  = $fbillnoentry ;
    		$data['fbillno']  = $fbillno ;
    		SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_YbaojiadanCB_NoteJZ' , ['fbillnoentry'=> "'".$fbillnoentry."'" ],true);
    		$result = SqlServerUtil::sqlsrvCreate($this->SqlServer ,'gz_YbaojiadanCB_NoteJZ' , $data);
    		
    	}elseif( in_array($FRepKey, [ '30011' ]) ){
    		//30011  正式报价(后续)
    		$fbillnoentry = $request->get('fbillnoentry');
    		$data['fbillnoentry']  = $fbillnoentry ;
    		$data['fbillno']  = $fbillno ;
    		SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_YbaojiadanCB_NoteHT' , ['fbillnoentry'=> "'".$fbillnoentry."'" ],true);
    		$result = SqlServerUtil::sqlsrvCreate($this->SqlServer ,'gz_YbaojiadanCB_NoteHT' , $data);
    		
    	}else{
	    	$data['fbillno']  = $fbillno ;
	    	SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_YbaojiadanCB_Note' , ['fbillno'=> "'".$fbillno."'" ],true);
	    	$result = SqlServerUtil::sqlsrvCreate($this->SqlServer ,'gz_YbaojiadanCB_Note' , $data);
    	}
    	
    	showMsg(0,'成功' , $result) ;
    }
    
    
    /**
    * 业务需求复制 
    * @date: 2023年4月28日 下午7:45:33
    * @author: juyi
    */
    public function ywCopy(Request $request){
    	$result=[];
    	$FRepKey = $request->get('FRepKey');
    	$opername = $request->get('opername');
    	$fbillno = $request->get('fbillno');
    	$data = $request->get('data');
    	if(empty($data)){
    		showMsg(400,'数据为空'  );
    	}
    	$result = [];
    	$db = columnBiao($FRepKey);
    	$getVexTableColumnData = $this->getVexBillColumn($FRepKey  ) ;
    	//dd(111,$getVexTableColumnData);
    		foreach ($getVexTableColumnData as $kc=>$vc)
    		{
    			if( ( empty($data[$vc['frepfld']]) || $data[$vc['frepfld']] =='.00' ) && $vc['freptype'] == 131 ){
    				$data[$vc['frepfld']] =0;
    			}
    			if( empty($data[$vc['frepfld']])  && ($vc['freptype'] == 202 || $vc['freptype'] == 200 || is_null($data[$vc['frepfld']])) ){
    				$data[$vc['frepfld']] = '';
    			}
    			$result[$vc['frepfld']] = $data[$vc['frepfld']] ;
    	}
    	$aaTmp = explode('+', $result['fsxtaishu'])   ;
    	// fsxtaishu
    	$result['fqty'] =  intval(array_shift( $aaTmp ))   ;
    	$result['fbillno'] = $this->getDanHao($FRepKey) ;
    	// 启动事务
    	if (sqlsrv_begin_transaction($this->SqlServer) === false) {
    		die(print_r(sqlsrv_errors(), true));
    	}
    	
    	$ins = SqlServerUtil::sqlsrvCreateTosql($this->SqlServer ,$db , $result);
    	 
    	if($ins){
    		sqlsrv_commit($this->SqlServer);
    		showMsg(0,'成功');
    	}else{
    		sqlsrv_rollback($this->SqlServer);
    		showMsg(1,'失败');
    	}
    	
    }
    
  
    /**
    * 后续加账  30010
    * 3001002 代表 加账单据 
    * @date: 2023年5月8日 下午6:12:36
    * @author: juyi
    */
    public function FhouxuJZ(Request $request){
    	$result=[];
    	$FRepKey = $request->get('FRepKey');
    	$opername = $request->get('opername');
    	$fbillno = $request->get('fbillno');
    	$data = $request->get('data');
    	if(empty($data)){
    		showMsg(400,'数据为空'  );
    	}
    	$fbillnoentry = $data['fbillnoentry'] ;
    	$fkeywordStr  = "" ;
    	if ($request->has('keyword') and $request->keyword != '' and !empty($request->keyword)) {
    		$keyword = $request->keyword  ;
    		$fkeywordStr=" and ( charindex('{$keyword}',u1.fname)>0 or charindex('{$keyword}',u1.fcode)>0   )" ;
    	}
    	//dd(222);
    	//业务需求 加账
    	$Sql ="  select  u1.fbrand  ,v1.fcode  ,v1.fprodno ,u1.fname  ,v1.fywqty ,u1.fzjQty 
    	,v1.fnote from gz_Yjiazhangcbf_HouXu  v1  left join gz_YjiazhangcbfSet u1 on u1.fcode =  v1.fcode
    	where 1=1 and v1.fbillnoentry = '{$fbillnoentry}'  {$fkeywordStr} ";
//     	echo $Sql; die;
    	$data = SqlServerUtil::execTosqlOK($this->SqlServer,$Sql);
    	$result=[];
    	if($data){
    		$result = arraykeyToLower($data);
    		foreach ($result as $k1=>&$v1)
    		{
    			foreach ($v1 as $k2=>$v2)
    			{
    				if( $v1[$k2] ==='.00' || $v1[$k2]  ==='.0000'  || $v1[$k2]  ==='.000' || $v1[$k2]  ==='.000000' || ($v1[$k2]>0 && $v1[$k2]<1) ){
    					$v1[$k2] = floatval($v2);
    				}
    				 
    			}
    		}
    	}
    	showMsg(0,'成功',$result) ; 
    	
    }
    
    /**
    * 后续加账 --删除 
    * @date: 2023年5月8日 下午6:24:15
    * @author: juyi
    */
    public function FhouxuJZDel(Request $request){
    	$FRepKey = $request->get('FRepKey');
    	$opername = $request->get('opername');
    	$fbillno = $request->get('fbillno');
    	$data = $request->get('data');
    	$removeRecords = $request->get('removeRecords');
    	$row = $request->row ;
    	$fbillnoentry = $row['fbillnoentry'];
    	
    	if(empty($removeRecords)){
    		showMsg(400,'修改数据为空' ) ;
    	}
    	
    	$arrTT = array_column($removeRecords,'fcode');
    	$fcode =join("','", $arrTT);
    	$fcodeStr = "'".$fcode ."'";
    	$db = 'gz_Yjiazhangcbf_HouXu';
    	$db_BJ = 'gz_Yjiazhangcbf_HouXu_BAOJIA';
    	$del = true;$delBJ= true;
    	// 启动事务
    	if (sqlsrv_begin_transaction($this->SqlServer) === false) {
    		die(print_r(sqlsrv_errors(), true));
    	}
    	
    	// 删除 sqlsrvDeleteBack
    	$sql = " delete from $db where fbillnoentry = '{$fbillnoentry}' and  fcode in ({$fcodeStr}) ";
    	$sqlbj = " delete from $db_BJ where fbillnoentry = '{$fbillnoentry}' and  fcode in ({$fcodeStr}) ";
    	
    	$del =  SqlServerUtil::sqlexecTosql($this->SqlServer,$sql );
    	$delBJ =  SqlServerUtil::sqlexecTosql($this->SqlServer,$sqlbj  );
    	
    	if($del  ){
    		sqlsrv_commit($this->SqlServer);
    		showMsg(0,'成功');
    	}else {
    		sqlsrv_rollback($this->SqlServer);
    		showMsg(1,'失败');
    	}
    }
    
    
    /**
    *  后续加账 --- 保存
    * @date: 2023年5月8日 下午6:25:40
    * @author: juyi
    */
    public function FhouxuJZSave(Request $request){
    	$FRepKey = $request->get('FRepKey');
    	$opername = $request->get('opername');
    	$fbillno = $request->get('fbillno');
    	$data = $request->get('data');
    	$updateRecords = $request->updateRecords ;
    	$row = $request->row ;
    	$fbillnoentry = $row['fbillnoentry'];
    	if(empty($updateRecords)){
    		showMsg(400,'修改数据为空' ) ; 
    	}
    	$arr= [] ; 
    	$db = 'gz_Yjiazhangcbf_HouXu';
    	$db_BJ = 'gz_Yjiazhangcbf_HouXu_BAOJIA';
    	$update = true;$updateBJ= true;
    	if($updateRecords){
    		foreach ($updateRecords as $k=>$v)
    		{
    			$arr =[];
    			//$arr[$k]['fbillnoentry'] = $v['fbillnoentry'];
    			//$arr[$k]['fcode'] = $v['fcode'];
    			$arr['fywqty'] = $v['fywqty'];
    			$arr['fnote'] = $v['fnote'];
    			$update = SqlServerUtil::exeupdateTosql($this->SqlServer,$db,$arr ,['fbillnoentry'=>$fbillnoentry , 'fcode'=>$v['fcode'] ]);
    		}
    		
    		$arrTT = array_column($updateRecords,'fcode');
    		$fcode =join("','", $arrTT);
    		$fcodeStr = "'".$fcode ."'";
    		
    		$resZS  = SqlServerUtil::execToSql($this->SqlServer, "select v1.fbm,v1.fsxqty,v1.fax, v1.foriamount,v1.fbrand,v1.fcode,u2.fisgongshijs,
			u1.fywqty from gz_Yjiazhangcbf_HouXu_BAOJIA  v1
			left join gz_Yjiazhangcbf_HouXu u1 on u1.fbillnoentry = v1.fbillnoentry and v1.fcode = u1.fcode
			left join gz_Yjiazhangcbfset u2 on v1.fcode = u2.fcode
			where v1.fbillnoentry ='{$fbillnoentry}' and v1.fcode in ({$fcodeStr}) " );
    		//参数设置
    		$csSetData = $this->getSystemProfile(['FSetRGzhuangshiCJPrice' ,'FSetFFAX' ,'FSetChaiYouPrice'
    				,'FSetQiGangPrice' ,'FSetRanqiPrice' , ]);
    		//后续报价
    		foreach ($resZS as $k1=>$v1)
    		{
    			$arr =[];
    			//$arr[$k]['fbillnoentry'] = $v['fbillnoentry'];
    			//$arr[$k]['fcode'] = $v['fcode'];
    			$arr['fywqty'] = $v1['fywqty'];
    			if($v1['fbm'] == 'CG'){
    				$arr['fallamount'] = getJZguanzeCG($v1['foriamount'], $v1['fywqty'], $v1['fisgongshijs']  ) ;
    			}elseif($v1['fbm'] == 'JS'){
    				$arr['fallamount'] = getJZguanzeJS( $v1['foriamount'] ,$v1['fywqty'],$v1['fsxqty'] ,$v1['fisgongshijs'],$csSetData,(1+$v1['fax']/100) );
    			}else{
    				//其他
    				$arr['fallamount']= round( $v1['foriamount'] *$v1['fywqty'] ,2 );	
    			}
    			$updateBJ = SqlServerUtil::exeupdateTosql($this->SqlServer,$db_BJ,$arr ,['fbillnoentry'=>$fbillnoentry , 'fcode'=>$v1['fcode'] ]);
    		}
    		
    	}
    	if($update && $updateBJ ){
    		showMsg(0,'成功' ) ; 
    	}else{
    		showMsg(400,'失败' ) ; 
    	}
    	
    }
    
    /**
    * 船检费其他 -- 自动生成 
    * @date: 2023年9月19日 下午5:35:59
    * @author: juyi
    */
    public function cjsBaseQR(Request $request){
    	$FRepKey = $request->get('FRepKey');
    	$opername = $request->get('opername');
    	$data = $request->get('data');
    	if(empty($data)){
    		showMsg(400,'数据选择为空，请检查！' ) ; 
    	}
    	$fjybjbillno = $data['fbillno'];
    	
    	$resCG =[
    			'fjybjbillno'=> $fjybjbillno ,
    			'fpower'=> $data['fhtpower'] ,
    			'ftype'=> $data['fchuanjishe'] ,
    			'fcreatetime'=> getCurrentTime(),
    	];
    	
    	SqlServerUtil::sqlsrvDeleteBack($this->SqlServer,'gz_YchuanjianfQT' , ['fjybjbillno'=> "'".$fjybjbillno."'" ],true);
    	SqlServerUtil::sqlsrvCreate($this->SqlServer ,'gz_YchuanjianfQT' , $resCG);
    	$this->writeLog(getMkName($FRepKey),'确认新增' , $FRepKey , $data ,$opername );
    	
    	showMsg(0,'成功' ) ; 
    }
    
    /**
    * 船检费 其他  -- 保存 
    * @date: 2023年9月20日 下午3:16:15
    * @author: juyi
    */
    public function cjsBaseSave(Request $request){
    	
    	dd($request ->all() ); 
    	
    	showMsg(0,'成功' ) ; 
    	
    }
    

}
